| | |
| | | } |
| | | |
| | | /** |
| | | * 验证新用户密码 |
| | | * 验证用户实体类 |
| | | */ |
| | | public String validateNewPwd(UserEntity entity) { |
| | | public String validateUserEntity(UserEntity entity) { |
| | | if (entity == null) { |
| | | return "没有找到用户"; |
| | | } |
| | | if (StringHelper.isEmpty(entity.getUid())) { |
| | | return "用户ID不能为空"; |
| | | } |
| | | if (StringHelper.isEmpty(entity.getPwd())) { |
| | | return "密码不能为空"; |
| | | return "用户密码不能为空"; |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 验证新用户密码 |
| | | */ |
| | | public String validateNewPwd(UserEntity entity) { |
| | | try { |
| | | String str = validateUserEntity(entity); |
| | | if (str != null) { |
| | | return str; |
| | | } |
| | | |
| | | // 解密 |
| | | String uid = RsaHelper.decrypt(entity.getUid()); |
| | | String pwd = RsaHelper.decrypt(entity.getPwd()); |
| | | if (!StringHelper.checkPwdValid(pwd)) { |
| | | return "密码不符合要求"; |
| | |
| | | |
| | | String newPwd = Md5Helper.reverse(Md5Helper.generate(pwd)); |
| | | entity.setPwd(newPwd); |
| | | entity.setUid(uid); |
| | | |
| | | return null; |
| | | } catch (Exception ex) { |
| | |
| | | * 验证老用户密码 |
| | | */ |
| | | public String validateOldPwd(UserEntity entity) { |
| | | if (entity == null) { |
| | | return "没有找到用户"; |
| | | } |
| | | if (StringHelper.isEmpty(entity.getPwd())) { |
| | | return "用户密码不能为空"; |
| | | } |
| | | |
| | | try { |
| | | String str = validateUserEntity(entity); |
| | | if (str != null) { |
| | | return str; |
| | | } |
| | | if (StringHelper.isEmpty(entity.getSalt())) { |
| | | return "新密码不能为空"; |
| | | } |
| | | |
| | | String uid = RsaHelper.decrypt(entity.getUid()); |
| | | String pwd = RsaHelper.decrypt(entity.getPwd()); |
| | | String salt = RsaHelper.decrypt(entity.getSalt()); |
| | | |
| | | UserEntity ue = selectUser(entity.getId()); |
| | | UserEntity ue = selectByUid(uid); |
| | | if (ue == null) { |
| | | return "没有找到用户"; |
| | | } |
| | |
| | | String newPwd = Md5Helper.reverse(Md5Helper.generate(salt)); |
| | | entity.setPwd(newPwd); |
| | | entity.setSalt(null); |
| | | entity.setUid(uid); |
| | | |
| | | return null; |
| | | } catch (Exception ex) { |
| | |
| | | } catch (Exception ex) { |
| | | return "密码解密失败"; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置密码错误缓存 |
| | | * |
| | | * @param ue |
| | | */ |
| | | public void setPwdErrCache(UserEntity ue) { |
| | | String key = RedisCacheKey.signPwdError(ue.getUid()); |
| | | Object objCount = redisService.get(key); |
| | | |
| | | int count = objCount == null ? 1 : (int) objCount + 1; |
| | | redisService.put(key, count, SettingData.PWD_ERR_TIME, TimeUnit.MINUTES); |
| | | } |
| | | } |