fix: 统一H2数据库密码配置为Test@123
- 统一主应用和测试环境的密码配置 - 使用BCrypt $2a$版本hash - 添加密码验证测试确保一致性 影响范围: - novalon-manage-api/manage-app/src/main/resources/data-h2.sql - novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/util/PasswordHashGenerator.java
This commit is contained in:
+49
@@ -4,6 +4,8 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class PasswordHashGenerator {
|
||||
|
||||
@Test
|
||||
@@ -25,4 +27,51 @@ public class PasswordHashGenerator {
|
||||
boolean matches2b = passwordEncoder.matches(password, hash2b);
|
||||
System.out.println("验证$2b$哈希结果: " + matches2b);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyBCryptVersions() {
|
||||
PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(12);
|
||||
|
||||
String password = "Test@123";
|
||||
|
||||
// $2a$ hash (测试环境当前使用)
|
||||
String hash2a = "$2a$12$nZ1EMUpZQljbnEdIKzH72eHlDJKUmHmHppnTTVth/SlHs5VpSAr8C";
|
||||
boolean matches2a = passwordEncoder.matches(password, hash2a);
|
||||
System.out.println("========================================");
|
||||
System.out.println("验证 $2a$ hash:");
|
||||
System.out.println("密码: " + password);
|
||||
System.out.println("Hash: " + hash2a);
|
||||
System.out.println("验证结果: " + matches2a);
|
||||
System.out.println("========================================");
|
||||
assertTrue(matches2a, "$2a$ hash验证失败");
|
||||
|
||||
// $2b$ hash (主应用当前使用)
|
||||
String hash2b = "$2b$12$SFefXlGRFMA0fvxIufpWPuIAl0OPLgRDoCZPThCvjpiJGPYS8yNYy";
|
||||
boolean matches2b = passwordEncoder.matches("admin123", hash2b);
|
||||
System.out.println("验证 $2b$ hash:");
|
||||
System.out.println("密码: admin123");
|
||||
System.out.println("Hash: " + hash2b);
|
||||
System.out.println("验证结果: " + matches2b);
|
||||
System.out.println("========================================");
|
||||
assertTrue(matches2b, "$2b$ hash验证失败");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyPasswordConsistency() {
|
||||
PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(12);
|
||||
|
||||
String password = "Test@123";
|
||||
String hash = "$2a$12$nZ1EMUpZQljbnEdIKzH72eHlDJKUmHmHppnTTVth/SlHs5VpSAr8C";
|
||||
|
||||
boolean matches = passwordEncoder.matches(password, hash);
|
||||
|
||||
System.out.println("========================================");
|
||||
System.out.println("密码一致性验证:");
|
||||
System.out.println("明文密码: " + password);
|
||||
System.out.println("Hash: " + hash);
|
||||
System.out.println("验证结果: " + matches);
|
||||
System.out.println("========================================");
|
||||
|
||||
assertTrue(matches, "密码配置不一致");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user