Java Code Examples for org.mindrot.jbcrypt.BCrypt#gensalt()

The following examples show how to use org.mindrot.jbcrypt.BCrypt#gensalt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserController.java    From javalin-website-example with Apache License 2.0 5 votes vote down vote up
public static void setPassword(String username, String oldPassword, String newPassword) {
    if (authenticate(username, oldPassword)) {
        String newSalt = BCrypt.gensalt();
        String newHashedPassword = BCrypt.hashpw(newSalt, newPassword);
        // Update the user salt and password
    }
}
 
Example 2
Source File: BCryptProvider.java    From gocd-filebased-authentication-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public String hash(CliArguments arguments) {
    final String salt = BCrypt.gensalt(arguments.cost());

    final String hashedPasswd = BCrypt.hashpw(arguments.password(), salt);

    return format("{0}={1}", arguments.username(), hashedPasswd);
}
 
Example 3
Source File: BCryptPasswordHashProvider.java    From keycloak-bcrypt with Apache License 2.0 4 votes vote down vote up
private String generateBCryptSalt(int iterations) {
    int logRounds = iterations == -1 ? iterationsToLogRounds(defaultIterations) : iterationsToLogRounds(iterations);
    return BCrypt.gensalt(logRounds);
}
 
Example 4
Source File: BCryptEncryptionModule.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public HashDescriptor getHash(String content) {
    String salt = BCrypt.gensalt();
    String hash = BCrypt.hashpw(content, salt);
    return new HashDescriptor(hash, salt);
}
 
Example 5
Source File: BCryptEncryptionModule.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public String getPasswordHash(UUID userId, String password) {
    String salt = BCrypt.gensalt();
    return BCrypt.hashpw(password, salt);
}
 
Example 6
Source File: PasswordEncoder.java    From jersey-jwt with MIT License 2 votes vote down vote up
/**
 * Hashes a password using BCrypt.
 *
 * @param plainTextPassword
 * @return
 */
public String hashPassword(String plainTextPassword) {
    String salt = BCrypt.gensalt();
    return BCrypt.hashpw(plainTextPassword, salt);
}