Skip to content
Snippets Groups Projects
Commit 4b784851 authored by Fakhri Mahendra's avatar Fakhri Mahendra
Browse files

feat: update SecurityUtil.java to accomodate hash and salt

parent e1b91d6c
No related merge requests found
package edujin.util;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import java.security.SecureRandom;
......@@ -20,8 +22,20 @@ public class SecurityUtil {
return sb.toString();
}
public static void main(String[] args) {
String randomString = generateRandomString(32); // Change 16 to desired length
System.out.println("Random String: " + randomString);
public static String hashPassword(String password) {
// Already salted
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(12);
return encoder.encode(password);
}
public static Boolean checkPassword(String enteredPassword, String hashedPassword) {
return BCrypt.checkpw(enteredPassword, hashedPassword);
}
public static void main (String[] args) {
String pw = "vjrcYqbuYaCnLCDE7bm7ZU99lGfEZCJx";
String hashedPassword = hashPassword(pw);
Boolean b = BCrypt.checkpw(pw, hashedPassword);
System.out.println(b);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment