Grails 圣杯3&x2B;Spring安全核心插件确认密码
今天大家好,我已经开始学习使用SpringSecurityCore插件的Grails3,但是我在密码验证方面遇到了困难。当用户注册时,我希望他键入密码和确认密码。如果不散列密码,一切都会好的。我想在数据库中对我的密码进行编码,但使用编码我无法比较这两个密码 这是我的班级:Grails 圣杯3&x2B;Spring安全核心插件确认密码,grails,spring-security,Grails,Spring Security,今天大家好,我已经开始学习使用SpringSecurityCore插件的Grails3,但是我在密码验证方面遇到了困难。当用户注册时,我希望他键入密码和确认密码。如果不散列密码,一切都会好的。我想在数据库中对我的密码进行编码,但使用编码我无法比较这两个密码 这是我的班级: @EqualsAndHashCode(includes='username') @ToString(includes='username', includeNames=true, includePackage=false) c
@EqualsAndHashCode(includes='username')
@ToString(includes='username', includeNames=true, includePackage=false)
class User implements Serializable {
private static final long serialVersionUID = 1
transient springSecurityService
String username
String password
String confirmPass
boolean enabled = true
boolean accountExpired
boolean accountLocked
boolean passwordExpired
User(String username, String password) {
this()
this.username = username
this.password = password
this.confirmPass = password
}
Set<Role> getAuthorities() {
UserRole.findAllByUser(this)*.role
}
// because of that I can't compare password and confirmPass
def beforeInsert() {
encodePassword()
}
def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}
protected void encodePassword() {
password = springSecurityService?.passwordEncoder ? springSecurityService.encodePassword(password) : password
}
static transients = ['springSecurityService']
static constraints = {
username blank: false, unique: true
password blank: false, size: 5..60, password: true, display: false, validator: { val, obj ->
if (!obj.id && !obj.password) {
return 'validation.user.password' // my message
}
}
confirmPass blank: // now I'm stuck here, I've tried isPasswordValid() but won't work cuz of 'salt' What shout go here?
}
static mapping = {
password column: '`password`'
}
}
@EqualsAndHashCode(包括='username')
@ToString(includes='username',includeNames=true,includePackage=false)
类用户实现可序列化{
私有静态最终长SerialVersionId=1
临时安全服务
字符串用户名
字符串密码
字符串确认过程
布尔启用=真
布尔帐户已过期
布尔帐户锁定
布尔密码过期
用户(字符串用户名、字符串密码){
这()
this.username=用户名
this.password=密码
this.confirmPass=密码
}
设置getAuthorities(){
UserRole.findallbyser(此)*.role
}
//因此,我无法比较密码和确认密码
def beforeInsert(){
encodePassword()
}
def beforeUpdate(){
if(isDirty(‘密码’)){
encodePassword()
}
}
受保护的无效密码(){
密码=springSecurityService?.passwordEncoder?springSecurityService.encodePassword(密码):密码
}
静态瞬态=['springSecurityService']
静态约束={
用户名空白:false,唯一:true
密码空白:false,大小:5..60,密码:true,显示:false,验证器:{val,obj->
如果(!obj.id&&!obj.password){
返回“validation.user.password”//我的消息
}
}
confirmPass blank://现在我被困在这里了,我尝试了isPasswordValid(),但不起作用,因为“salt”什么叫喊?
}
静态映射={
密码列:“`password`”
}
}
我应该怎么做才能使它工作(两个有效密码相同,然后在数据库中存储编码的密码)。您已经尝试了哪些不工作的密码?尝试比较两个密码并使用isPasswordValid(),但没有成功。