gpt4 book ai didi

Grails Spring-Security-如何比较密码-

转载 作者:行者123 更新时间:2023-12-04 05:30:39 24 4
gpt4 key购买 nike

我使用的是SpringSecurity 2.0-RC2,希望用户在在线时可以更改密码。

我的用户域类具有以下内容

def beforeInsert() {
encodePassword()
}

def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}

protected void encodePassword() {
password = springSecurityService.encodePassword(password)
}

要检查用户是否输入了正确的当前密码,我正在 Controller 中执行以下操作:
if (springSecurityService.encodePassword(params.currentPassword) == user.password) {    

...但是令人惊讶的是(对我而言)检查始终失败。如果我这样做,那就更奇怪了:
            println springSecurityService.encodePassword(params.currentPassword)
println springSecurityService.encodePassword(params.currentPassword)

我在控制台中收到以下内容

$ 2a $ 10 $ sWt7mUSHPFT.Np6m.gXyl.h8tWqblJbwtzQ6EQeMHxXMoGwOffC3e
$ 2a $ 10 $ lwHz1SkNlW8ibznt.mOiruAg5eG/BTtsjM7ChyYVBvamRcrL8tucm

(就像会有盐-但我自己没有配置一个)

我的设置或多或少是默认设置;除了这三个域类的软件包名称。

由于自从严酷的日子以来记录下降,我问这里是否有人知道我做错了什么...

最佳答案

试试这个

def passwordEncoder
...
passwordEncoder.isPasswordValid(user.password, params.currentPassword, null)

有关更多详细信息,请参见 this post

关于Grails Spring-Security-如何比较密码-,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24115991/

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