App用户密码调整
This commit is contained in:
@@ -34,7 +34,7 @@ public interface IUserSetService extends IService<UserSet> {
|
||||
* @author xy
|
||||
* @date 2022/1/21 12:39
|
||||
*/
|
||||
String updatePassword(String id,String newPassword);
|
||||
String updatePassword(String id,String newPassword, Boolean result);
|
||||
|
||||
/**
|
||||
* 功能描述: 未登录 修改用户密码
|
||||
|
||||
@@ -228,7 +228,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, User> impleme
|
||||
if (Objects.isNull(user)){
|
||||
throw new BusinessException(UserResponseEnum.LOGIN_USERNAME_NOT_FOUND);
|
||||
}
|
||||
String secretPassword = userSetService.updatePassword(userId, password);
|
||||
String secretPassword = userSetService.updatePassword(userId, password,false);
|
||||
user.setPassword(secretPassword);
|
||||
user.setPwdValidity(LocalDateTime.now());
|
||||
user.setLoginTime(LocalDateTime.now());
|
||||
@@ -252,7 +252,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, User> impleme
|
||||
if (Objects.isNull(user)){
|
||||
throw new BusinessException(UserResponseEnum.LOGIN_USERNAME_NOT_FOUND);
|
||||
}
|
||||
String secretPassword = userSetService.updatePassword(user.getId(), password);
|
||||
String secretPassword = userSetService.updatePassword(user.getId(), password,false);
|
||||
user.setPassword(secretPassword);
|
||||
user.setPwdValidity(LocalDateTime.now());
|
||||
user.setLoginTime(LocalDateTime.now());
|
||||
|
||||
@@ -349,7 +349,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
||||
|
||||
@Override
|
||||
public boolean updatePassword(String id, String password) {
|
||||
String secretPassword = userSetService.updatePassword(id, password);
|
||||
String secretPassword = userSetService.updatePassword(id, password,true);
|
||||
User user = lambdaQuery().eq(User::getId, id).one();
|
||||
user.setPassword(secretPassword);
|
||||
user.setPwdValidity(LocalDateTime.now());
|
||||
|
||||
@@ -65,15 +65,15 @@ public class UserSetServiceImpl extends ServiceImpl<UserSetMapper, UserSet> impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public String updatePassword(String id,String newPassword) {
|
||||
public String updatePassword(String id,String newPassword,Boolean result) {
|
||||
String password = getSecretPassword(newPassword);
|
||||
return updatePsd(id,password);
|
||||
return updatePsd(id,password,result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String updateFirstPassword(String id, String newPassword, String name, String ip) {
|
||||
String password = getSecretPasswordNotLogin(newPassword, name, ip);
|
||||
return updatePsd(id,password);
|
||||
return updatePsd(id,password,true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,7 +110,52 @@ public class UserSetServiceImpl extends ServiceImpl<UserSetMapper, UserSet> impl
|
||||
* @param password
|
||||
* @return
|
||||
*/
|
||||
private String updatePsd(String id, String password) {
|
||||
private String updatePsd(String id, String password,Boolean result) {
|
||||
Sm4Utils sm4;
|
||||
String psd,strSm4;
|
||||
if (result){
|
||||
String standard = PatternRegex.PASSWORD_REGEX;
|
||||
Pattern pattern = Pattern.compile(standard);
|
||||
Matcher m=pattern.matcher(password);
|
||||
if (!m.find()){
|
||||
throw new BusinessException(UserResponseEnum.SPECIAL_PASSWORD);
|
||||
}
|
||||
//密码是否需要复杂校验
|
||||
} else {
|
||||
String standard = PatternRegex.APP_PASSWORD_REGEX;
|
||||
Pattern pattern = Pattern.compile(standard);
|
||||
Matcher m=pattern.matcher(password);
|
||||
if (!m.find()){
|
||||
throw new BusinessException(UserResponseEnum.APP_PASSWORD);
|
||||
}
|
||||
}
|
||||
UserSet userSet = this.lambdaQuery().eq(UserSet::getUserId, id).one();
|
||||
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
|
||||
userQueryWrapper.eq("sys_user.id",id);
|
||||
User user = userMapper.selectOne(userQueryWrapper);
|
||||
String secretPassword = user.getPassword();
|
||||
if (Objects.isNull(userSet)){
|
||||
UserSet newUserSet = new UserSet();
|
||||
String secretKey = PubUtils.randomCode(16);
|
||||
newUserSet.setSecretKey(secretKey);
|
||||
sm4 = new Sm4Utils(secretKey);
|
||||
strSm4 = sm4.encryptData_ECB(password);
|
||||
newUserSet.setStandBy(strSm4);
|
||||
newUserSet.setUserId(id);
|
||||
this.save(newUserSet);
|
||||
psd = sm4.encryptData_ECB(strSm4 + secretKey);
|
||||
} else {
|
||||
sm4 = new Sm4Utils(userSet.getSecretKey());
|
||||
strSm4 = sm4.encryptData_ECB(password);
|
||||
psd = sm4.encryptData_ECB(strSm4 + userSet.getSecretKey());
|
||||
}
|
||||
if (Objects.equals(secretPassword,psd)){
|
||||
throw new BusinessException(UserResponseEnum.REPEAT_PASSWORD);
|
||||
}
|
||||
return psd;
|
||||
}
|
||||
|
||||
private String updateAppPsd(String id, String password) {
|
||||
Sm4Utils sm4;
|
||||
String psd,strSm4;
|
||||
String standard = PatternRegex.PASSWORD_REGEX;
|
||||
|
||||
Reference in New Issue
Block a user