19 lines
818 B
Java
19 lines
818 B
Java
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
|
public class PasswordTest {
|
|
public static void main(String[] args) {
|
|
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
|
String password = "admin123";
|
|
String storedHash = "$2a$10$YnS1.BqJb7hUdHk1p4pZKe8QnhZLf9mJ0jBZXlGzb3jVgQ8KHp2nq";
|
|
|
|
System.out.println("Testing password: " + password);
|
|
System.out.println("Stored hash: " + storedHash);
|
|
System.out.println("Matches: " + encoder.matches(password, storedHash));
|
|
|
|
// 也生成一个新的hash看看
|
|
String newHash = encoder.encode(password);
|
|
System.out.println("New hash for admin123: " + newHash);
|
|
System.out.println("New hash matches: " + encoder.matches(password, newHash));
|
|
}
|
|
}
|