fix(admin): Correct admin initialization and password salt compatibility
This commit is contained in:
+1
-1
@@ -49,7 +49,7 @@ public class AdminUserInitService implements ApplicationRunner {
|
||||
adminUser.setRealName("系统管理员");
|
||||
adminUser.setEmail("admin@example.com");
|
||||
adminUser.setStatus(1); // 正常状态
|
||||
adminUser.setSalt(null);
|
||||
adminUser.setSalt(passwordService.generateSalt());
|
||||
adminUser.setCreatedBy("system");
|
||||
adminUser.setUpdatedBy("system");
|
||||
adminUser.setCreateTime(LocalDateTime.now());
|
||||
|
||||
+1
-1
@@ -221,7 +221,7 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser
|
||||
} else {
|
||||
// 不更新密码
|
||||
adminUser.setPassword(null);
|
||||
adminUser.setSalt(null); // 同时不更新盐值
|
||||
adminUser.setSalt(""); // 使用空串兼容非空字段约束
|
||||
}
|
||||
|
||||
adminUser.setUpdatedBy(operator);
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@ public class PasswordServiceImpl implements PasswordService {
|
||||
|
||||
@Override
|
||||
public String generateSalt() {
|
||||
// BCrypt已包含盐值,此方法不再需要
|
||||
// 兼容历史表结构,salt 字段仍要求非空
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class PasswordServiceImpl implements PasswordService {
|
||||
public void setPassword(AdminUser user, String rawPassword) {
|
||||
// 直接使用BCrypt加密密码
|
||||
user.setPassword(passwordEncoder.encode(rawPassword));
|
||||
// 不再需要设置盐值
|
||||
user.setSalt(null);
|
||||
// BCrypt 已内置盐值,这里仅写入空串以兼容非空字段约束
|
||||
user.setSalt(generateSalt());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user