gpt4 book ai didi

spring - 如何在Grails中从Spring Security获取普通密码或解密密码?

转载 作者:行者123 更新时间:2023-12-02 15:05:46 25 4
gpt4 key购买 nike

我在Grails应用程序中使用 Spring Security插件。保存密码时,密码在数据库中为加密格式。我想给它发送普通密码。如何获得?

另一个Android应用程序使用了我的API。从我的API,我需要发送特定的用户密码。

最佳答案

如果您正在从db:读取密码,则将密码保存到数据库时,它们是hashed而不是encryptedthe process involved in hashing is not reversible,因此简单的答案是:不,您不能。

您可以在将密码保存到数据库时使用加密(以便在遇到特殊情况(例如您的情况)时可以解密密码),但这不是一个好主意that is why hashing functions are preferred to encryption algorithm for saving passwords

但是,如果您确实需要这样做并且知道如何处理风险,则可以拦截对user.save()的调用,特别是拦截对密码进行编码的beforeInsert()beforeUpdate()方法。

因此,用户的beforeInsert()beforeUpdate()方法将如下所示:

beforeInsert(){

...
yourApiService.sendPassword(password)
...
password = securityService.encodePassword(password)
...

}


beforeUpdate(){

...
if(isDirty('password')){

yourApiService.sendPassword(password)
...
password = securityService.encodePassword(password)

}
...

}

关于spring - 如何在Grails中从Spring Security获取普通密码或解密密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31383043/

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