jNetLib/src/main/java/jnet/lib/PasswordHashing.java

37 lines
1.1 KiB
Java

package jnet.lib;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
/**
* Hash hesla a jeho kontrola
* vyžaduje knihovnu spring-security-crypto-5.8.0.jar a apache-commons-logging-1.2.jar
* @author cucky
*/
public class PasswordHashing {
public static String hash(String string){
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
return passwordEncoder.encode(string);
}
public static boolean verify(String rawPassword, String hashedPassword){
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
return passwordEncoder.matches(rawPassword, hashedPassword);
}
// public static String hash(String password){
// Argon2 argon2 = Argon2Factory.create();
// String hash = argon2.hash(10, 65536, 1, password);
// return hash;
// }
//
// public static boolean verify(String rawPassword, String hashedPassword){
// Argon2 argon2 = Argon2Factory.create();
// return argon2.verify(hashedPassword, rawPassword);
//
// }
}