44323
2024-04-23 16b704d18a875d1fb63827aaa507790ba2bef5be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.stylefeng.guns.modular.system.util;
 
import org.mindrot.jbcrypt.BCrypt;
 
public class PasswordUtils {
    
    public static String hashPassword(String password) {
        return BCrypt.hashpw(password, BCrypt.gensalt());
    }
    
    public static boolean checkPassword(String password, String hashedPassword) {
        return BCrypt.checkpw(password, hashedPassword);
    }
    
    public static void main(String[] args) {
        String password = "myPassword";
        String hashedPassword = hashPassword(password);
        System.out.println("Hashed Password: " + hashedPassword);
        
        boolean isPasswordCorrect = checkPassword(password, hashedPassword);
        System.out.println("Is Password Correct? " + isPasswordCorrect);
    }
}