我一直试图让这个工作半天。我正在尝试使用Seymour Cakes和Burt Beckwith的bcrypt插件在我的grails应用程序中使用密码加密:
http://grails.org/plugin/bcrypt
我已将相应的依赖项放在BuildConfig.groovy中,而在我的控制器中,我正在尝试运行一个简单的测试:
def bcryptService
String goodpwd = "good"
String badpwd = "bad"
String encryptedpwd = goodpwd.encodeAsBcrypt()
println " "
println "Good Password: " + goodpwd
println "Bad Password: " + badpwd
println "Bcrypt Hash Of Good Password: " + encryptedpwd
println "Matching good password: " + (goodpwd.encodeAsBcrypt().equals(encryptedpwd))
println "Matching bad password: " + (badpwd.encodeAsBcrypt().equals(encryptedpwd))
println "Bcrypt Service's match result: " + bcryptservice.checkPassword(goodpwd, encryptedpwd)
但我明白了:
Good Password: good
Bad Password: bad
Bcrypt Hash Of Good Password: $2a$10$KvQOvmA4QjH4.JEk4.V2/uXYf8UjKJaUccDijQWG3RkBgAA2LOndS
Matching good password: false
Matching bad password: false
Error |
2014-05-21 14:20:05,935 [http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver - MissingPropertyException occurred when processing request: [POST] /FatcaOne_0
No such property: bcryptservice for class: com.twc.fatcaone.AdminController. Stacktrace follows:
Message: No such property: bcryptservice for class: com.twc.fatcaone.AdminController
Line | Method
->> 71 | doCall in com.twc.fatcaone.AdminController$_closure5$$EOevDLMH
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
有时它会这样做,它抱怨bcryptService是null。我不明白我做错了什么不能注入这种依赖。非常感谢任何帮助。
答案 0 :(得分:1)
如果您的第一块代码在方法中,请确保您使用
def bcryptService
排除这段代码并将其放在控制器的类级别。