当前位置: 首页>>代码示例>>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;未经允许,请勿转载。