feat: 登录密码改用 BCrypt 校验
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.guo.learningprogresstracker.utils;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mindrot.jbcrypt.BCrypt;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class BCryptPasswordGeneratorTest {
|
||||
|
||||
@Test
|
||||
void generatePasswordHash() {
|
||||
String password = System.getProperty("password", "admin");
|
||||
int rounds = Integer.parseInt(System.getProperty("rounds", "10"));
|
||||
|
||||
String hash = BCrypt.hashpw(password, BCrypt.gensalt(rounds));
|
||||
|
||||
System.out.println("BCrypt hash:");
|
||||
System.out.println(hash);
|
||||
System.out.println("SQL:");
|
||||
System.out.printf("UPDATE `user` SET `user_password` = '%s' WHERE `user_name` = 'admin';%n", hash);
|
||||
|
||||
assertTrue(BCrypt.checkpw(password, hash));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user