當前位置: 首頁>>代碼示例>>Java>>正文


Java BCrypt.gensalt方法代碼示例

本文整理匯總了Java中org.mindrot.jbcrypt.BCrypt.gensalt方法的典型用法代碼示例。如果您正苦於以下問題:Java BCrypt.gensalt方法的具體用法?Java BCrypt.gensalt怎麽用?Java BCrypt.gensalt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.mindrot.jbcrypt.BCrypt的用法示例。


在下文中一共展示了BCrypt.gensalt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testGensaltInt

import org.mindrot.jbcrypt.BCrypt; //導入方法依賴的package包/類
/**
 * Test method for 'BCrypt.gensalt(int)'
 */
public void testGensaltInt() {
	System.out.print("BCrypt.gensalt(log_rounds):");
	for (int i = 4; i <= 12; i++) {
		System.out.print(" " + Integer.toString(i) + ":");
		for (int j = 0; j < test_vectors.length; j += 4) {
			String plain = test_vectors[j][0];
			String salt = BCrypt.gensalt(i);
			String hashed1 = BCrypt.hashpw(plain, salt);
			String hashed2 = BCrypt.hashpw(plain, hashed1);
			assertEquals(hashed1, hashed2);
			System.out.print(".");
		}
	}
	System.out.println("");
}
 
開發者ID:svenkubiak,項目名稱:jBCrypt,代碼行數:19,代碼來源:TestBCrypt.java

示例2: hashPassword

import org.mindrot.jbcrypt.BCrypt; //導入方法依賴的package包/類
@Override
public String hashPassword(String password) {
    verifyPasswordInput(password);

    String salt = BCrypt.gensalt(LOG_ROUNDS, new SecureRandom());
    return BCrypt.hashpw(password, salt);
}
 
開發者ID:erikns,項目名稱:webpoll,代碼行數:8,代碼來源:SecurePasswordHasher.java

示例3: setPassword

import org.mindrot.jbcrypt.BCrypt; //導入方法依賴的package包/類
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
    }
}
 
開發者ID:tipsy,項目名稱:javalin-website-example,代碼行數:8,代碼來源:UserController.java

示例4: generateSalt

import org.mindrot.jbcrypt.BCrypt; //導入方法依賴的package包/類
@Override
public String generateSalt() {
    SecureRandom random = new SecureRandom();

    byte bytes[] = new byte[20];
    random.nextBytes(bytes);

    return BCrypt.gensalt(10, random);
}
 
開發者ID:Atypon-OpenSource,項目名稱:wayf-cloud,代碼行數:10,代碼來源:CryptFacadeBcryptImpl.java

示例5: setPassword

import org.mindrot.jbcrypt.BCrypt; //導入方法依賴的package包/類
@Override
public boolean setPassword(String username, String oldPassword, String newPassword) {
    Optional<User> userOptional = authenticateAndGet(username, oldPassword);
    if (userOptional.isPresent()) {
        String newSalt = BCrypt.gensalt();
        String newHashedPassword = BCrypt.hashpw(newPassword, newSalt);
        User user = userOptional.get();
        user.setSalt(newSalt);
        user.setHashedPassword(newHashedPassword);
        userDao.saveUser(user);
        return true;
    } else {
        return false;
    }
}
 
開發者ID:oleg-vasiliev,項目名稱:sparkjava-boilerplate,代碼行數:16,代碼來源:UserServiceImpl.java

示例6: hash

import org.mindrot.jbcrypt.BCrypt; //導入方法依賴的package包/類
@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);
}
 
開發者ID:gocd,項目名稱:gocd-filebased-authentication-plugin,代碼行數:9,代碼來源:BCryptProvider.java

示例7: registration

import org.mindrot.jbcrypt.BCrypt; //導入方法依賴的package包/類
public static User registration(AccessUser accessUser){
	String salt = BCrypt.gensalt (8);
	return new User (
			accessUser.getUserName (),
			BCrypt.hashpw ( accessUser.getPassword (), salt ),
			salt
	);
}
 
開發者ID:akimaleo,項目名稱:JavaREST-WorldHistoryTracker,代碼行數:9,代碼來源:WebServiceSecurity.java

示例8: setPassword

import org.mindrot.jbcrypt.BCrypt; //導入方法依賴的package包/類
public static void setPassword(String username, String oldPassword, String newPassword) {
    if (authenticate(username, oldPassword)) {
        String newSalt = BCrypt.gensalt();
        String newPasswordHash = BCrypt.hashpw(newSalt, newPassword);
        // Save to DB
    }
}
 
開發者ID:lyuboraykov,項目名稱:codenvy-spark-java,代碼行數:8,代碼來源:UserController.java

示例9: register

import org.mindrot.jbcrypt.BCrypt; //導入方法依賴的package包/類
public TiramisuResponse register() throws NotFoundException {
	log.info("User Controller Register Method");

	if (this.request.getMethod().equals("POST")) {
		
		UserModel user = new UserModel();
		user.setUsername(this.getRequest().getParameter("user_username"));
		user.setEmail(this.getRequest().getParameter("user_email"));
		user.setActive(false);
		
		// Use the salt and pepper, plus hash, to save the password.
		String salt = BCrypt.gensalt();
		
		// Using the apache commons codec library, convert the password and pepper to a hashed password.
		// Have to use 256 here, because 512 exceeds the max length of BCrypt
		String hmacPassword = HmacUtils.hmacSha256Hex(TiramisuConfiguration.pepper, this.getRequest().getParameter("user_password"));
		
		// Hash the password.
		String hash = BCrypt.hashpw(hmacPassword, salt);
		
		// Store the hash.
		user.setPassword(hash);
		
		// Finally save the user.
		this.save(user);
		
		// Add a flash message.
		this.getResponse().addFlashMessage("New user created");
		
		// Redirect to the users index.
		return this.redirect("/tiramisu/users", 303);
	}

	// Render the create form.
	this.getResponse().setTemplate("/users/create.vm");
	this.getResponse().setPageTitle("Create new user");

	return this.getResponse();
}
 
開發者ID:arcynum,項目名稱:tiramisu,代碼行數:40,代碼來源:UserController.java

示例10: LobbyLoginValidator

import org.mindrot.jbcrypt.BCrypt; //導入方法依賴的package包/類
public LobbyLoginValidator() {
  this(
      LobbyContext.lobbyPropertyReader(),
      new BadWordController(),
      new BannedMacController(),
      new BannedUsernameController(),
      new UserController(),
      new RsaAuthenticator(),
      () -> BCrypt.gensalt());
}
 
開發者ID:triplea-game,項目名稱:triplea,代碼行數:11,代碼來源:LobbyLoginValidator.java

示例11: testGensalt

import org.mindrot.jbcrypt.BCrypt; //導入方法依賴的package包/類
/**
 * Test method for 'BCrypt.gensalt()'
 */
public void testGensalt() {
	System.out.print("BCrypt.gensalt(): ");
	for (int i = 0; i < test_vectors.length; i += 4) {
		String plain = test_vectors[i][0];
		String salt = BCrypt.gensalt();
		String hashed1 = BCrypt.hashpw(plain, salt);
		String hashed2 = BCrypt.hashpw(plain, hashed1);
		assertEquals(hashed1, hashed2);
		System.out.print(".");
	}
	System.out.println("");
}
 
開發者ID:svenkubiak,項目名稱:jBCrypt,代碼行數:16,代碼來源:TestBCrypt.java

示例12: encryptPassword

import org.mindrot.jbcrypt.BCrypt; //導入方法依賴的package包/類
private void encryptPassword(String plaintextPassword) {
    String salt = BCrypt.gensalt(LOG_ROUNDS);
    this.hashedPassword = BCrypt.hashpw(plaintextPassword, salt);
}
 
開發者ID:maillouxc,項目名稱:git-rekt,代碼行數:5,代碼來源:Employee.java

示例13: JBCryptPasswordEncoder

import org.mindrot.jbcrypt.BCrypt; //導入方法依賴的package包/類
/**
 * Use the default salt generated by {@link BCrypt#gensalt()}.
 */
public JBCryptPasswordEncoder() {
    this.salt = BCrypt.gensalt();
}
 
開發者ID:yaochi,項目名稱:pac4j-plus,代碼行數:7,代碼來源:JBCryptPasswordEncoder.java

示例14: encryptThenSetPassword

import org.mindrot.jbcrypt.BCrypt; //導入方法依賴的package包/類
public void encryptThenSetPassword(String password_plaintext){
    String salt = BCrypt.gensalt(12);
    this.password = BCrypt.hashpw(password_plaintext, salt);
    this.lastUpdateTime = System.currentTimeMillis();
}
 
開發者ID:bekce,項目名稱:oauthly,代碼行數:6,代碼來源:User.java

示例15: hashPassword

import org.mindrot.jbcrypt.BCrypt; //導入方法依賴的package包/類
public static String hashPassword(String password_plaintext)
{
  String salt = BCrypt.gensalt(workload);
  String hashed_password = BCrypt.hashpw(password_plaintext, salt);
  return (hashed_password);
}
 
開發者ID:Malow,項目名稱:GladiatorManager,代碼行數:7,代碼來源:Password.java


注:本文中的org.mindrot.jbcrypt.BCrypt.gensalt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。