gpt4 book ai didi

java - 如何使用org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder解密存储在mongodb中的密码?

转载 作者:行者123 更新时间:2023-12-02 05:33:44 29 4
gpt4 key购买 nike

密码使用org.springframework.security.crypto.bcrypt.BCryptPasswordEncoderdecrypt存储在mongoDB中。由于此 API 以加密格式将密码存储在数据库中,即使我存储相同的密码,它也会以不同的方式加密并存储在数据库中。现在我的问题是如何比较输入的密码是否已存储在数据库中。我怎样才能实现我的目标,你能解释一下吗?

最佳答案

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
}

关于java - 如何使用org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder解密存储在mongodb中的密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56186629/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com