gpt4 book ai didi

java - 更改当前用户的密码时需要验证什么?

转载 作者:行者123 更新时间:2023-12-01 07:22:23 24 4
gpt4 key购买 nike

我正在开发一个 spring-mvc 项目,该项目使用 spring-security 进行身份验证。我还使用加密对密码进行编码并存储在数据库中。

现在我正在尝试更改密码功能。通常我们有旧密码新密码

所以我有一个问题。

  1. 用户登录后才能更改密码。那么是否需要再次验证旧密码

  2. 如果我们必须验证如何在 Spring 中使用旧密码进行编码?

我正在使用 BCryptPasswordEncoder 对密码进行编码。

最佳答案

matches方法BCryptPasswordEncoder对此很有用:

if (passwordEncoder.matches(changePasswordForm.getOldPassword(),
user.getPassword())) {
// ok
} else {
// wrong old password
}

关于java - 更改当前用户的密码时需要验证什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32520889/

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