blob: 407ea58da9d86b45e2be93b74f113a8b1d00a352 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
package database;
import at.favre.lib.crypto.bcrypt.BCrypt;
public class BcryptHelper {
private static int difficulty=10;
public static String hashPasword(String password){
String passwordH=BCrypt.withDefaults().hashToString(10, password.toCharArray());
return passwordH;
}
public static boolean checkPassword(String password_plaintext, String stored_hash) {
boolean password_verified = false;
if(null == stored_hash || !stored_hash.startsWith("$2a$"))
throw new java.lang.IllegalArgumentException("Invalid hash");
password_verified = BCrypt.verifyer().verify(password_plaintext.toCharArray(), stored_hash).verified;
return password_verified;
}
}
|