// Path: src/main/java/com/civilizer/security/UserDetailsService.java
// public final class UserDetailsService
//     implements org.springframework.security.core.userdetails.UserDetailsService {
//     
//     public static final int ENCRYPTION_STRENGTH     = 11;
//     public static final String CREDENTIAL_FILE      = ".cvz.pc";
//     private static final String HASHED_DEFAULT_PW   = "$2a$10$w.Jjtx0mrjH4E.DxQEmBZu.D1oCBKy26utS8KCOSn0fmq1xs2GXiK";
//     
//     private static UserDetails createUserDetails(String username, String passwordCode) {
//         List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
//         authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
//         return new User(username, passwordCode, authorities);
//     }
// 
//     private static UserDetails getDefaultCredential(String username) {
//         if (username.equals("owner")) {
//             return createUserDetails(username, HASHED_DEFAULT_PW);
//         }
//         return null;
//     }
//     
//     public static boolean encodingMatches(String raw, String encoded) {
//         return new BCryptPasswordEncoder(UserDetailsService.ENCRYPTION_STRENGTH)
//             .matches(raw, encoded);
//     }
//     
//     private static UserDetails getCustomCredential(String username, String usernameCode, String passwordCode) {
//         if (encodingMatches(username, usernameCode)) {
//             return createUserDetails(username, passwordCode);
//         }
//         return null;
//     }
//     
//     public static File getCredentialFile() {
//         final String homePath = System.getProperty(AppOptions.PRIVATE_HOME_PATH);
//         final String credFilePath = FsUtil.getAbsolutePath(CREDENTIAL_FILE, homePath);
//         return new File(credFilePath);
//     }
//     
//     public static void saveCustomCredential(String username, String password, String oldPwHash)
//             throws IOException, InvalidParameterException {
//         
//         final BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(ENCRYPTION_STRENGTH);
//         final List<String> lines = new ArrayList<>();
//         if (username == null || username.isEmpty()) {
//             throw new InvalidParameterException();
//         }
//         lines.add(encoder.encode(username));
//         if (password == null || password.isEmpty()) {
//             if (oldPwHash != null && !oldPwHash.isEmpty())
//                 lines.add(oldPwHash);
//             else
//                 throw new InvalidParameterException();
//         }
//         else
//             lines.add(encoder.encode(password));
//         FileUtils.writeLines(UserDetailsService.getCredentialFile(), lines, "\n");
//     }
//     
//     public static boolean authenticatePassword(String pw) {
//         final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
//         final Object principal = auth.getPrincipal();
//         if (principal instanceof UserDetails) {
//             final UserDetails ud = (UserDetails) principal;
//             return encodingMatches(pw, ud.getPassword());
//         }
//         return false;
//     }
// 
//     @Override
//     public UserDetails loadUserByUsername(String username)
//             throws UsernameNotFoundException {
//         final Logger logger = LoggerFactory.getLogger(UserDetailsService.class);
//         final File credentialFile = getCredentialFile();
//         UserDetails output = null;
//         boolean customCredential = credentialFile.isFile();
//         
//         if (customCredential) {
//             try {
//                 final String content = FileUtils.readFileToString(credentialFile);
//                 final String[] tmp = content.split("\n");
//                 logger.info("processing custom credential...");
//                 output = getCustomCredential(username, tmp[0], tmp[1]);
//             } catch (IOException e) {
//                 logger.error("Error in reading the file {}", credentialFile.getAbsoluteFile());
//                 e.printStackTrace();
//                 logger.error("Switching to default credential...");
//                 customCredential = false;
//             }
//         }
//         
//         if (customCredential == false) {
//             logger.info("processing default credential...");
//             output = getDefaultCredential(username);
//         }
//         
//         if (output != null) {
//             return output;
//         }
//         
//         logger.info("authentication for {} failed!", username);
//         throw new BadCredentialsException("Bad Credentials");
//     }
//     
// }


import java.io.Serializable;
import org.primefaces.context.RequestContext;
import com.civilizer.security.UserDetailsService;
package com.civilizer.web.view;




@SuppressWarnings("serial")
public final class AuthenticationBean implements Serializable {
    
// Path: src/main/java/com/civilizer/security/UserDetailsService.java
// public final class UserDetailsService
//     implements org.springframework.security.core.userdetails.UserDetailsService {
//     
//     public static final int ENCRYPTION_STRENGTH     = 11;
//     public static final String CREDENTIAL_FILE      = ".cvz.pc";
//     private static final String HASHED_DEFAULT_PW   = "$2a$10$w.Jjtx0mrjH4E.DxQEmBZu.D1oCBKy26utS8KCOSn0fmq1xs2GXiK";
//     
//     private static UserDetails createUserDetails(String username, String passwordCode) {
//         List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
//         authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
//         return new User(username, passwordCode, authorities);
//     }
// 
//     private static UserDetails getDefaultCredential(String username) {
//         if (username.equals("owner")) {
//             return createUserDetails(username, HASHED_DEFAULT_PW);
//         }
//         return null;
//     }
//     
//     public static boolean encodingMatches(String raw, String encoded) {
//         return new BCryptPasswordEncoder(UserDetailsService.ENCRYPTION_STRENGTH)
//             .matches(raw, encoded);
//     }
//     
//     private static UserDetails getCustomCredential(String username, String usernameCode, String passwordCode) {
//         if (encodingMatches(username, usernameCode)) {
//             return createUserDetails(username, passwordCode);
//         }
//         return null;
//     }
//     
//     public static File getCredentialFile() {
//         final String homePath = System.getProperty(AppOptions.PRIVATE_HOME_PATH);
//         final String credFilePath = FsUtil.getAbsolutePath(CREDENTIAL_FILE, homePath);
//         return new File(credFilePath);
//     }
//     
//     public static void saveCustomCredential(String username, String password, String oldPwHash)
//             throws IOException, InvalidParameterException {
//         
//         final BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(ENCRYPTION_STRENGTH);
//         final List<String> lines = new ArrayList<>();
//         if (username == null || username.isEmpty()) {
//             throw new InvalidParameterException();
//         }
//         lines.add(encoder.encode(username));
//         if (password == null || password.isEmpty()) {
//             if (oldPwHash != null && !oldPwHash.isEmpty())
//                 lines.add(oldPwHash);
//             else
//                 throw new InvalidParameterException();
//         }
//         else
//             lines.add(encoder.encode(password));
//         FileUtils.writeLines(UserDetailsService.getCredentialFile(), lines, "\n");
//     }
//     
//     public static boolean authenticatePassword(String pw) {
//         final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
//         final Object principal = auth.getPrincipal();
//         if (principal instanceof UserDetails) {
//             final UserDetails ud = (UserDetails) principal;
//             return encodingMatches(pw, ud.getPassword());
//         }
//         return false;
//     }
// 
//     @Override
//     public UserDetails loadUserByUsername(String username)
//             throws UsernameNotFoundException {
//         final Logger logger = LoggerFactory.getLogger(UserDetailsService.class);
//         final File credentialFile = getCredentialFile();
//         UserDetails output = null;
//         boolean customCredential = credentialFile.isFile();
//         
//         if (customCredential) {
//             try {
//                 final String content = FileUtils.readFileToString(credentialFile);
//                 final String[] tmp = content.split("\n");
//                 logger.info("processing custom credential...");
//                 output = getCustomCredential(username, tmp[0], tmp[1]);
//             } catch (IOException e) {
//                 logger.error("Error in reading the file {}", credentialFile.getAbsoluteFile());
//                 e.printStackTrace();
//                 logger.error("Switching to default credential...");
//                 customCredential = false;
//             }
//         }
//         
//         if (customCredential == false) {
//             logger.info("processing default credential...");
//             output = getDefaultCredential(username);
//         }
//         
//         if (output != null) {
//             return output;
//         }
//         
//         logger.info("authentication for {} failed!", username);
//         throw new BadCredentialsException("Bad Credentials");
//     }
//     
// }


// Path: src/main/java/com/civilizer/web/view/AuthenticationBean.java
import java.io.Serializable;
import org.primefaces.context.RequestContext;
import com.civilizer.security.UserDetailsService;

package com.civilizer.web.view;




@SuppressWarnings("serial")
public final class AuthenticationBean implements Serializable {
    
    private String password = "";