本文整理汇总了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("");
}
示例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);
}
示例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
}
}
示例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);
}
示例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;
}
}
示例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);
}
示例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
);
}
示例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
}
}
示例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();
}
示例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());
}
示例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("");
}
示例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);
}
示例13: JBCryptPasswordEncoder
import org.mindrot.jbcrypt.BCrypt; //导入方法依赖的package包/类
/**
* Use the default salt generated by {@link BCrypt#gensalt()}.
*/
public JBCryptPasswordEncoder() {
this.salt = BCrypt.gensalt();
}
示例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();
}
示例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);
}