Grails Spring-Security - 如何比较密码 - [英] Grails Spring-Security -how to compare passwords-

查看:594
本文介绍了Grails Spring-Security - 如何比较密码 - 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的用户域类具有以下

使用SpringSecurity 2.0-RC2,并希望用户提供在线时更改密码的可能性。 >

  def beforeInsert(){
encodePassword()
}
$ b $ def beforeUpdate {
if(isDirty('password')){
encodePassword()
}
}

protected void encodePassword(){
密码= springSecurityService.encodePassword(密码)
}

检查用户是否进入正确的当前密码我在控制器中执行以下操作:

  if(springSecurityService.encodePassword(params.currentPassword)== user。密码){

...但是(对我来说)检查总是失败。甚至更奇怪,如果即时通讯这样做:

pre $ println springSecurityService.encodePassword(params.currentPassword)
println springSecurityService.encodePassword params.currentPassword)

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

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

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



我的设置或多或少是默认设置;



由于严重的日子,文档已经关闭了,我问了这里是否有人知道我做错了什么......

p>

解决方案

试试这个

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

有关更多详细信息,请参见此帖。 p>

Im using SpringSecurity 2.0-RC2 and want users to give the possibilty to change their passwords while they are online.

My User domain class has the following

def beforeInsert() {
    encodePassword()
}

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

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

To check whether the user was enterering the correct current password i was doing the following in a controller:

if (springSecurityService.encodePassword(params.currentPassword) == user.password) {    

... but surprsingly (for me) the check always fails. Even more strange if im doing this:

            println springSecurityService.encodePassword(params.currentPassword)
            println springSecurityService.encodePassword(params.currentPassword)

i receive the following in the console

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

(like there would be a salt - but i didnt configure one myself)

My Settings are more or less the default settings; except the package names of the three domain classes.

As the documention is down since severely days im asking here if somebody has a idea what im doing wrong...

解决方案

Try this

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

See this post for more detail.

这篇关于Grails Spring-Security - 如何比较密码 - 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆