public PasswordMatcher() { this.passwordService = new DefaultPasswordService(); }
public boolean passwordsMatch(Object submittedPlaintext, String saved) { ByteSource plaintextBytes = createByteSource(submittedPlaintext); Hash savedHash = parsableHashFormat.parse(saved); return passwordsMatch(submittedPlaintext, savedHash); HashRequest request = createHashRequest(plaintextBytes); Hash computed = this.hashService.computeHash(request); String formatted = this.hashFormat.format(computed);
public String encryptPassword(Object plaintext) { Hash hash = hashPassword(plaintext); checkHashFormatDurability(); return this.hashFormat.format(hash); }
DefaultHashService hashService = new DefaultHashService(); hashService.setHashIterations(HASH_ITERATIONS); // 500000 hashService.setHashAlgorithmName(Sha256Hash.ALGORITHM_NAME); hashService.setPrivateSalt(new SimpleByteSource(PRIVATE_SALT)); // Same salt as in shiro.ini, but NOT base64-encoded. hashService.setGeneratePublicSalt(true); DefaultPasswordService passwordService = new DefaultPasswordService(); passwordService.setHashService(hashService); String encryptedPassword = passwordService.encryptPassword("PasswordForThisUser");
@Inject public DefaultSecurityPasswordService(@Named("legacy") final PasswordService legacyPasswordService) { this.passwordService = new DefaultPasswordService(); this.legacyPasswordService = checkNotNull(legacyPasswordService); //Create and set a hash service according to our hashing policies DefaultHashService hashService = new DefaultHashService(); hashService.setHashAlgorithmName(DEFAULT_HASH_ALGORITHM); hashService.setHashIterations(DEFAULT_HASH_ITERATIONS); hashService.setGeneratePublicSalt(true); this.passwordService.setHashService(hashService); }
DefaultPasswordService passwordService = new DefaultPasswordService(); String encytptedPwd= passwordService.encryptPassword("your password");
public LegacyNexusPasswordService() { //Initialize and configure sha1 password service this.sha1PasswordService = new DefaultPasswordService(); DefaultHashService sha1HashService = new DefaultHashService(); sha1HashService.setHashAlgorithmName("SHA-1"); sha1HashService.setHashIterations(1); sha1HashService.setGeneratePublicSalt(false); this.sha1PasswordService.setHashService(sha1HashService); this.sha1PasswordService.setHashFormat(new HexFormat()); //Initialize and configure md5 password service this.md5PasswordService = new DefaultPasswordService(); DefaultHashService md5HashService = new DefaultHashService(); md5HashService.setHashAlgorithmName("MD5"); md5HashService.setHashIterations(1); md5HashService.setGeneratePublicSalt(false); this.md5PasswordService.setHashService(md5HashService); this.md5PasswordService.setHashFormat(new HexFormat()); }
@Configuration public class SecurityConfiguration { private static final String PRIVATE_SALT = "ourprivatesalt"; private PasswordService passwordService; private PasswordMatcher credentialsMatcher = new PasswordAndSystemCredentialsMatcher(); private AuthenticatingSecurityManager securityManager; @Bean public PasswordService passwordService() { if (passwordService == null) { DefaultPasswordService defaultPasswordService = new DefaultPasswordService(); passwordService = defaultPasswordService; DefaultHashService defaultHashService = (DefaultHashService) defaultPasswordService.getHashService(); defaultHashService.setPrivateSalt(new SimpleByteSource(PRIVATE_SALT)); } return passwordService; } @Bean public CredentialsMatcher credentialsMatcher() { credentialsMatcher.setPasswordService(passwordService()); return credentialsMatcher; }
@Override public boolean passwordsMatch(final Object plaintext, final Hash savedPasswordHash) { return passwordService.passwordsMatch(plaintext, savedPasswordHash); } }
@Override public String encryptPassword(Object plaintextPassword) throws IllegalArgumentException { return this.passwordService.encryptPassword(plaintextPassword); }
@Override public Hash hashPassword(Object plaintext) throws IllegalArgumentException { return this.passwordService.hashPassword(plaintext); }
@Override public void activateService() throws Exception { configuration.refresh(); PasswordRealmConfiguration config = configuration.get(); String algorithm = config.hashAlgorithmName().get(); Integer iterations = config.hashIterationsCount().get(); if( algorithm != null || iterations != null ) { DefaultHashService hashService = (DefaultHashService) passwordService.getHashService(); if( algorithm != null ) { hashService.setHashAlgorithmName( algorithm ); } if( iterations != null ) { hashService.setHashIterations( iterations ); } } }
@Inject public DefaultSecurityPasswordService(SecurityConfigurationManager securityConfiguration, @Named("legacy") PasswordService legacyPasswordService) { this.securityConfiguration = securityConfiguration; this.passwordService = new DefaultPasswordService(); this.legacyPasswordService = legacyPasswordService; //Create and set a hash service according to our hashing policies DefaultHashService hashService = new DefaultHashService(); hashService.setHashAlgorithmName(DEFAULT_HASH_ALGORITHM); hashService.setHashIterations(this.securityConfiguration.getHashIterations()); hashService.setGeneratePublicSalt(true); this.passwordService.setHashService(hashService); }
private static final DefaultPasswordService defaultPasswordService = new DefaultPasswordService(); defaultPasswordService.encryptPassword( Thread.currentThread().getName());
public LegacyNexusPasswordService() { //Initialize and configure sha1 password service this.sha1PasswordService = new DefaultPasswordService(); DefaultHashService sha1HashService = new DefaultHashService(); sha1HashService.setHashAlgorithmName("SHA-1"); sha1HashService.setHashIterations(1); sha1HashService.setGeneratePublicSalt(false); this.sha1PasswordService.setHashService(sha1HashService); this.sha1PasswordService.setHashFormat(new HexFormat()); //Initialize and configure md5 password service this.md5PasswordService = new DefaultPasswordService(); DefaultHashService md5HashService = new DefaultHashService(); md5HashService.setHashAlgorithmName("MD5"); md5HashService.setHashIterations(1); md5HashService.setGeneratePublicSalt(false); this.md5PasswordService.setHashService(md5HashService); this.md5PasswordService.setHashFormat(new HexFormat()); }
@Override public boolean passwordsMatch(final Object submittedPlaintext, final String encrypted) { //Legacy passwords can be hashed with sha-1 or md5, check both return sha1PasswordService.passwordsMatch(submittedPlaintext, encrypted) || md5PasswordService.passwordsMatch(submittedPlaintext, encrypted); } }
@Override public String encryptPassword( Object plaintextPassword ) throws IllegalArgumentException { return passwordService.encryptPassword( plaintextPassword ); }
@Override public Hash hashPassword(final Object plaintext) { return passwordService.hashPassword(plaintext); }
@Override public void activateService() throws Exception { configuration.refresh(); PasswordRealmConfiguration config = configuration.get(); String algorithm = config.hashAlgorithmName().get(); Integer iterations = config.hashIterationsCount().get(); if( algorithm != null || iterations != null ) { DefaultHashService hashService = (DefaultHashService) passwordService.getHashService(); if( algorithm != null ) { hashService.setHashAlgorithmName( algorithm ); } if( iterations != null ) { hashService.setHashIterations( iterations ); } } }
public PasswordMatcher() { this.passwordService = new DefaultPasswordService(); }