Example usage for org.springframework.security.crypto.bcrypt BCrypt gensalt

List of usage examples for org.springframework.security.crypto.bcrypt BCrypt gensalt

Introduction

In this page you can find the example usage for org.springframework.security.crypto.bcrypt BCrypt gensalt.

Prototype

public static String gensalt(String prefix) 

Source Link

Usage

From source file:cz.lbenda.coursing.service.AbstractPasswordGenerator.java

public final static String generatePassword(final String pass) {
    return BCrypt.hashpw(pass, BCrypt.gensalt(12));
}

From source file:org.jutge.joc.porra.utils.AccountUtils.java

public static final String generateActivationToken() {
    return BCrypt.gensalt(16).replace("/", "7").replace(".", "d");
}

From source file:hr.diskobolos.core.crypt.PasswordHashCalc.java

/**
 * This method can be used to generate a string representing an account
 * password suitable for storing in a database. It will be an OpenBSD-style
 * crypt(3) formatted hash string of length=60 The bcrypt workload is
 * specified in the above static variable, a value from 10 to 31. A workload
 * of 12 is a very reasonable safe default as of 2013. This automatically
 * handles secure 128-bit salt generation and storage within the hash.
 *
 * @param password_plaintext The account's plaintext password as provided
 * during account creation, or when changing an account's password.
 * @return String - a string of length 60 that is the bcrypt hashed password
 * in crypt(3) format.//  w w  w .  j  a va2s .  co  m
 */
public String hashPassword(String password_plaintext) {
    String salt = BCrypt.gensalt(workload);
    String hashed_password = BCrypt.hashpw(password_plaintext, salt);

    return (hashed_password);
}

From source file:org.unitedid.auth.client.factors.PasswordFactor.java

public PasswordFactor(String password, String credentialId, int rounds)
        throws UnsupportedEncodingException, NoSuchAlgorithmException {
    this(password, credentialId, BCrypt.gensalt(rounds));
}

From source file:org.openbaton.nfvo.security.authentication.CustomUserDetailsService.java

@Override
public void run(String... args) throws Exception {

    log.debug("Creating initial Users...");

    if (!inMemManager.userExists("admin")) {
        UserDetails admin = new org.springframework.security.core.userdetails.User("admin",
                BCrypt.hashpw(adminPwd, BCrypt.gensalt(12)), true, true, true, true,
                AuthorityUtils.createAuthorityList("ADMIN"));
        inMemManager.createUser(admin);/*from  w  w w .j a  v  a 2  s.co m*/
    } else {
        log.debug("Admin" + inMemManager.loadUserByUsername("admin"));
    }
    for (User user : userRepository.findAll()) {
        if (!user.getUsername().equals("admin") && !user.getUsername().equals("guest")) {
            UserDetails userDetails = new org.springframework.security.core.userdetails.User(user.getUsername(),
                    user.getPassword(), true, true, true, true, AuthorityUtils.createAuthorityList("USER"));
            inMemManager.createUser(userDetails);
        }
    }

    log.debug("Users in UserDetailManager: ");
    log.info("ADMIN: " + inMemManager.loadUserByUsername("admin"));
}

From source file:org.jutge.joc.porra.service.AccountService.java

/**
 * Assume password has been set as plain text
 * @param account//from w  ww .  j  a  va  2  s  . c  om
 */
public void approveAccount(final Account account) {
    this.logger.info("AccountService.approveAccount");
    // Create random salt and store a hashed password
    final String textPassword = account.getHashedPass();
    final String salt = BCrypt.gensalt(16);
    final String hashedPassword = BCrypt.hashpw(textPassword, salt);
    account.setSalt(salt);
    account.setHashedPass(hashedPassword);
    // status is now approved
    account.setStatus(AccountStatus.STATUS_APPROVED.name());
    this.accountRepo.save(account);
}