32 lines
823 B
Java
32 lines
823 B
Java
package httpServer.authorization;
|
|
|
|
import org.springframework.security.crypto.bcrypt.BCrypt;
|
|
|
|
import java.util.Scanner;
|
|
|
|
public class PasswordHasher {
|
|
|
|
public static String genSalt(){
|
|
return BCrypt.gensalt(14);
|
|
}
|
|
|
|
public static String hashPassword(String password, String salt) {
|
|
return BCrypt.hashpw(password, salt);
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
System.out.print("Enter password: ");
|
|
Scanner in = new Scanner(System.in);
|
|
String password = in.nextLine();
|
|
|
|
String salt = genSalt();
|
|
String hashed = hashPassword(password, salt);
|
|
|
|
System.out.println("Hashed Password: " + hashed);
|
|
|
|
// Example of verifying a password
|
|
/*
|
|
boolean matches = BCrypt.checkpw(plainPassword, storedHash);
|
|
*/
|
|
}
|
|
} |