密码使用 org.springframework.security.crypto.bcrypt.BCryptPasswordEncoderdecrypt 存储在 mongoDB 中。由于此 API 以加密格式将密码存储在 DB 中,即使我存储相同的密码,它也会以不同的方式加密并存储在 DB 中。现在我的问题是如何比较输入的密码是否已经存储在数据库中。我怎样才能实现我的目标,你能解释一下吗?
问问题
2789 次
1 回答
0
I found that I cannot exactly match the password but here is workaround
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String enteredNewPassword = // Password entered by user
String dbPassword = // Load hashed DB password
if (passwordEncoder.matches(enteredNewPassword, dbPassword)) {
//Password is Already exists in db need to store new password
} else {
// new Password
}
于 2019-05-17T14:36:22.133 回答