2014-09-25 60 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);