fix check bug

This commit is contained in:
Looly 2021-01-24 22:44:34 +08:00
parent bdb078b1ee
commit 221608b544
3 changed files with 23 additions and 1 deletions

View File

@ -21,6 +21,7 @@
* 【core 】 修复Console.input读取不全问题pr#263@Gitee
* 【core 】 修复URLUtil.encodeAll未检查空指针问题issue#I2CNPS@Gitee
* 【core 】 修复UrlBuilder.of的query中含有?丢失问题issue#I2CNPS@Gitee
* 【crypto 】 修复BCrypt.checkpw报错问题issue#1377@Github
-------------------------------------------------------------------------------------------------------------

View File

@ -511,7 +511,14 @@ public class BCrypt {
public static boolean checkpw(String plaintext, String hashed) {
byte[] hashed_bytes;
byte[] try_bytes;
String try_pw = hashpw(plaintext, hashed);
String try_pw;
try{
try_pw = hashpw(plaintext, hashed);
} catch (Exception ignore){
// 生成密文时错误直接返回false issue#1377@Github
return false;
}
hashed_bytes = hashed.getBytes(CharsetUtil.CHARSET_UTF_8);
try_bytes = try_pw.getBytes(CharsetUtil.CHARSET_UTF_8);
if (hashed_bytes.length != try_bytes.length) {

View File

@ -0,0 +1,14 @@
package cn.hutool.crypto.test.digest;
import cn.hutool.crypto.digest.BCrypt;
import org.junit.Assert;
import org.junit.Test;
public class BCryptTest {
@Test
public void checkpwTest(){
Assert.assertFalse(BCrypt.checkpw("xxx",
"$2a$2a$10$e4lBTlZ019KhuAFyqAlgB.Jxc6cM66GwkSR/5/xXNQuHUItPLyhzy"));
}
}