BCrypt.checkpw()无效的salt版本异常 [英] BCrypt.checkpw() Invalid salt version exception

查看:4297
本文介绍了BCrypt.checkpw()无效的salt版本异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的Play 2.1中使用BCrypt进行身份验证。 Java应用程序,但当我试图验证用户时,我得到无效的盐版本异常



这是我的堆栈跟踪

  play.api.Application $$ anon $ 1:执行异常[[IllegalArgumentException:盐无效版本]] 
at play.api.Application $ class.handleError(Application.scala:289)〜[play_2.10.jar:2.1.0]
at play.api.DefaultApplication.handleError(Application.scala: 383)[play_2.10.jar:2.1.0]
at play.core.server.netty.PlayDefaultUpstreamHandler $$ anon $ 2 $$ anonfun $ handle $ 1.apply(PlayDefaultUpstreamHandler.scala:132)[play_2.10 .jar:2.1.0]
at play.core.server.netty.PlayDefaultUpstreamHandler $$ anon $ 2 $$ anonfun $ handle $ 1.apply(PlayDefaultUpstreamHandler.scala:128)[play_2.10.jar:2.1.0 ]
at play.api.libs.concurrent.PlayPromise $$ anonfun $ extend1 $ 1.apply(Promise.scala:113)[play_2.10.jar:2.1.0]
at play.api。 libs.concurrent.PlayPromise $$ anonfun $ extend1 $ 1.apply(Promise.scala:113)[play_2.10.jar:2.1.0]
java.lang.IllegalArgumentException:无效的salt版本
在org.mindrot.jbcrypt.BCrypt.hashpw(BCrypt.java:664)〜[jbcrypt-0.3m.jar:na]
at org.mindrot.jbcrypt.BCrypt.checkpw(BCrypt.java:763)〜[jbcrypt-0.3m.jar:na]
at model.operations.DistrictOperations.authenticate(DistrictOperations.java:24)〜[na: na]
at controllers.Application.authenticateDistrict(Application.java:26)〜[na:na]
at Routes $$ anonfun $ routes $ 1 $$ anonfun $ applyOrElse $ 2 $$ anonfun $ apply $ 2。 apply(routes_routing.scala:133)〜[na:na]
at Routes $$ anonfun $ routes $ 1 $$ anonfun $ applyOrElse $ 2 $$ anonfun $ apply $ 2.apply(routes_routing.scala:133)〜[na :na]

我正在使用以下maven仓库: http://mvnrepository.com/artifact/org.mindrot/jbcrypt/0.3m



我的代码基于文档,因此

  district.setPassword(BCrypt.hashpw(json。 findPath(passwo rd)。getTextValue(),BCrypt.gensalt())); 

用于保存密码(我也检查密码为空)

  BCrypt.checkpw(password,d.getPassword()); 

用于检查输入的密码是否正确,其中password是String并且d.getPassword()是哈希密码。



我不知道这是否是相关信息,但确切地说,我使用hibernate作为ORM和PostgreSQL 8.4作为DB。 b
$ b

我有点困在这里,所以我问是否有人可以帮助我。

解决方案

对于这个问题,我感到非常抱歉。我在代码中只有一个错误,它将简单的字符串保存到数据库而不是BCrypted。它完全是从代码的其他部分调用的。


I'm trying to implement authentication using BCrypt, in my Play 2.1. Java application, but I'm getting Invalid salt version exception when I'm trying to authenticate the user.

This is my stack trace

play.api.Application$$anon$1: Execution exception[[IllegalArgumentException: Invalid salt version]]
at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10.jar:2.1.0]
at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1.0]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:132) [play_2.10.jar:2.1.0]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:128) [play_2.10.jar:2.1.0]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.0]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.0]
java.lang.IllegalArgumentException: Invalid salt version
at org.mindrot.jbcrypt.BCrypt.hashpw(BCrypt.java:664) ~[jbcrypt-0.3m.jar:na]
at org.mindrot.jbcrypt.BCrypt.checkpw(BCrypt.java:763) ~[jbcrypt-0.3m.jar:na]
at model.operations.DistrictOperations.authenticate(DistrictOperations.java:24) ~[na:na]
at controllers.Application.authenticateDistrict(Application.java:26) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$2$$anonfun$apply$2.apply(routes_routing.scala:133) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$2$$anonfun$apply$2.apply(routes_routing.scala:133) ~[na:na]

I'm using following maven repository: http://mvnrepository.com/artifact/org.mindrot/jbcrypt/0.3m

My code is based on the documentation, thus

district.setPassword(BCrypt.hashpw(json.findPath("password").getTextValue(), BCrypt.gensalt()));    

For saving the password (I'm also checking the password for being null)

BCrypt.checkpw(password, d.getPassword());

For checking if the entered password is correct, where password is String and d.getPassword() is hashed password.

I don't know if this is relevant information, but to be precise I'm using hibernate for ORM and PostgreSQL 8.4 as DB.

I'm kind of stuck in here so I'm asking if anyone could help me out. Than you very much in advance.

解决方案

I'm very sorry for bothering with this question. I had just one bug in the code that was saving plain string to the DB instead of the BCrypted one. It was whole called from some other part of code.

这篇关于BCrypt.checkpw()无效的salt版本异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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