/** * @param passwordEncoder the password encoder to set */ public void setPasswordEncoder(PasswordEncoder passwordEncoder) { this.emptyPassword = passwordEncoder.encode(""); }
/** * The digest algorithm to use Supports the named * <a href="http://java.sun.com/j2se/1.4.2/docs/guide/security/CryptoSpec.html#AppA"> * Message Digest Algorithms</a> in the Java environment. * * @param algorithm */ public MessageDigestPasswordEncoder(String algorithm) { this.digester = new Digester(algorithm, 1); }
/** * Create a new Digester. * @param algorithm the digest algorithm; for example, "SHA-1" or "SHA-256". * @param iterations the number of times to apply the digest algorithm to the input */ public Digester(String algorithm, int iterations) { // eagerly validate the algorithm createDigest(algorithm); this.algorithm = algorithm; setIterations(iterations); }
@Override public boolean matches(CharSequence rawPassword, String prefixEncodedPassword) { if (rawPassword == null && prefixEncodedPassword == null) { return true; } String id = extractId(prefixEncodedPassword); PasswordEncoder delegate = this.idToPasswordEncoder.get(id); if (delegate == null) { return this.defaultPasswordEncoderForMatches .matches(rawPassword, prefixEncodedPassword); } String encodedPassword = extractEncodedPassword(prefixEncodedPassword); return delegate.matches(rawPassword, encodedPassword); }
@Bean public static NoOpPasswordEncoder passwordEncoder() { return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance(); }
private String digest(String salt, CharSequence rawPassword) { if (rawPassword == null) { rawPassword = ""; } String saltedPassword = rawPassword + salt; byte[] saltedPasswordBytes = Utf8.encode(saltedPassword); Md4 md4 = new Md4(); md4.update(saltedPasswordBytes, 0, saltedPasswordBytes.length); byte[] digest = md4.digest(); String encoded = encode(digest); return salt + encoded; }
/** * Takes a previously encoded password and compares it with a rawpassword after mixing * in the salt and encoding that value * * @param rawPassword plain text password * @param encodedPassword previously encoded password * @return true or false */ public boolean matches(CharSequence rawPassword, String encodedPassword) { String salt = extractSalt(encodedPassword); String rawPasswordEncoded = digest(salt, rawPassword); return PasswordEncoderUtils.equals(encodedPassword.toString(), rawPasswordEncoded); }
/** * Takes a previously encoded password and compares it with a rawpassword after mixing * in the salt and encoding that value * * @param rawPassword plain text password * @param encodedPassword previously encoded password * @return true or false */ public boolean matches(CharSequence rawPassword, String encodedPassword) { String salt = extractSalt(encodedPassword); String rawPasswordEncoded = digest(salt, rawPassword); return PasswordEncoderUtils.equals(encodedPassword.toString(), rawPasswordEncoded); }
/** * Sets the number of iterations for which the calculated hash value should be * "stretched". If this is greater than one, the initial digest is calculated, the * digest function will be called repeatedly on the result for the additional number * of iterations. * * @param iterations the number of iterations which will be executed on the hashed * password/salt value. Defaults to 1. */ public void setIterations(int iterations) { this.digester.setIterations(iterations); }
public byte[] digest() { byte[] resBuf = new byte[HASH_SIZE]; digest(resBuf, 0, HASH_SIZE); return resBuf; }
Md4() { reset(); }
@Override public String encode(CharSequence rawPassword) { return passwordEncoder.encode(rawPassword); } };
@Override public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception { oauthServer .tokenKeyAccess("permitAll()") .checkTokenAccess("isAuthenticated()") .passwordEncoder(NoOpPasswordEncoder.getInstance()); }
/** * Create a new Digester. * @param algorithm the digest algorithm; for example, "SHA-1" or "SHA-256". * @param iterations the number of times to apply the digest algorithm to the input */ public Digester(String algorithm, int iterations) { // eagerly validate the algorithm createDigest(algorithm); this.algorithm = algorithm; setIterations(iterations); }
/** * The digest algorithm to use Supports the named * <a href="http://java.sun.com/j2se/1.4.2/docs/guide/security/CryptoSpec.html#AppA"> * Message Digest Algorithms</a> in the Java environment. * * @param algorithm */ public MessageDigestPasswordEncoder(String algorithm) { this.digester = new Digester(algorithm, 1); }
/** * Sets the number of iterations for which the calculated hash value should be * "stretched". If this is greater than one, the initial digest is calculated, the * digest function will be called repeatedly on the result for the additional number * of iterations. * * @param iterations the number of iterations which will be executed on the hashed * password/salt value. Defaults to 1. */ public void setIterations(int iterations) { this.digester.setIterations(iterations); }
private void prepareTimingAttackProtection() { if (this.userNotFoundEncodedPassword == null) { this.userNotFoundEncodedPassword = this.passwordEncoder.encode(USER_NOT_FOUND_PASSWORD); } }
@Override public String encode(CharSequence rawPassword) { return PREFIX + this.idForEncode + SUFFIX + this.passwordEncoderForEncode.encode(rawPassword); }