Files
masi-3ds-cypher/src/main/java/httpServer/authorization/PasswordHasher.java
2025-12-10 09:12:12 +01:00

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);
*/
}
}