2014-09-25 50 views
0

我试图使用Spring's BCrypt implementation。我注意到checkpw()方法需要2个参数:明文密码和哈希。如果不包含盐分,该方法如何验证这一点?Spring的BCrypt实现

+0

为什么不使用'BCryptPasswordEncoder'类呢?附:看[也是这个问题](http://stackoverflow.com/questions/277044/do-i-need-to-store-the-salt-with-bcrypt?rq=1)。 – 2014-09-25 23:54:32

+0

只要进一步添加主要问题,您想用checkpw()功能实现什么功能?此外,Branislav为类似的问题指出了一个很好的答案。 – Aeseir 2014-09-26 01:28:53

回答

2

它可以验证,它不是神奇的--BCrypt编码的散列包含盐。您可以将盐存储在变量中以检查它:

String salt = BCrypt.gensalt(); 
String pw_hash = BCrypt.hashpw(plain_password, salt); 

System.out.println(salt); 
System.out.println(pw_hash);