如何使用Bcrypt存储和读取密码
- 论坛
- 如何使用Bcrypt存储和读取密码
12 浏览
如何使用Bcrypt存储和读取密码
我在使用BCrypt时遇到了问题。
我想以安全的方式存储用户密码,因此我使用Spring的BCrypt来加密密码。
我现在面临的问题是BCrypt生成了一个随机的盐值,当然,密码不能被解密。
但是我该如何处理登录呢?
private PasswordEncoder encoder = new BCryptPasswordEncoder(); public String encryptPassword(String password) { String encryptedValue = encoder.encode(password); Assert.isTrue(encoder.matches(password, encryptedValue)); return encryptedValue; }
我需要做什么来确保用户输入凭据时密码匹配呢?
String encryptedPassword = encryptionGenerator.encryptPassword(loginCredentials.getPassword());
然后我尝试使用Hibernate从数据库中读取
FROM Login WHERE email = :email AND password = :password AND email_confirmed = 1"