@Override public String encodePassword(String password, Object salt) { try { return "{CRYPT}" + md5Crypt.crypt(password); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("No MD5 Algorithm", e); } }
public String encodePassword( String password, Object salt ) { try { return "{CRYPT}" + md5Crypt.crypt( password ); } catch ( NoSuchAlgorithmException e ) { throw new RuntimeException( "No MD5 Algorithm", e ); } }
@Override public boolean isPasswordValid(String encPassword, String inputPassword, Object salt) { try { String encryptedPassword = encPassword; if (encryptedPassword.startsWith("{crypt}") || encryptedPassword.startsWith("{CRYPT}")) { encryptedPassword = encryptedPassword.substring("{crypt}".length()); } int lastDollar = encryptedPassword.lastIndexOf('$'); String realSalt = encryptedPassword.substring("$1$".length(), lastDollar); String check = md5Crypt.crypt(inputPassword, realSalt); return check.equals(encryptedPassword); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("No MD5 Algorithm", e); } }
public boolean isPasswordValid( String encPassword, String inputPassword, Object salt ) { try { String encryptedPassword = encPassword; if ( encryptedPassword.startsWith( "{crypt}" ) || encryptedPassword.startsWith( "{CRYPT}" ) ) { encryptedPassword = encryptedPassword.substring( "{crypt}".length() ); } int lastDollar = encryptedPassword.lastIndexOf( '$' ); String realSalt = encryptedPassword.substring( "$1$".length(), lastDollar ); String check = md5Crypt.crypt( inputPassword, realSalt ); return check.equals( encryptedPassword ); } catch ( NoSuchAlgorithmException e ) { throw new RuntimeException( "No MD5 Algorithm", e ); } }
/** * Encrypts a password using FreeBSD-style md5-based encryption * * @param password The cleartext password to be encrypted * @return The encrypted password, or an empty string on error * @throws java.security.NoSuchAlgorithmException * if java.security * does not support MD5 */ public final String crypt(String password) throws java.security.NoSuchAlgorithmException { StringBuilder salt = new StringBuilder(); SecureRandom randgen = new SecureRandom(); while (salt.length() < 8) { int index = (int) (randgen.nextFloat() * itoa64.length()); salt.append(itoa64.substring(index, index + 1)); } return crypt(password, salt.toString()); }
/** * Encrypts a password using FreeBSD-style md5-based encryption * @param password The cleartext password to be encrypted * @throws java.security.NoSuchAlgorithmException if java.security * does not support MD5 * @return The encrypted password, or an empty string on error */ public final String crypt(String password) throws java.security.NoSuchAlgorithmException { StringBuilder salt = new StringBuilder(); SecureRandom randgen = new SecureRandom(); while (salt.length() < 8) { int index = (int) (randgen.nextFloat() * itoa64.length()); salt.append(itoa64.substring(index, index+1)); } return crypt(password, salt.toString()); }