用户密码加密存储

master
chen 4 years ago
parent b3cba9f9c7
commit ee059ea106
  1. 13
      src/main/java/com/yipin/liuwanr/service/UserInfoService.java
  2. 31
      src/main/java/com/yipin/liuwanr/util/MD5.java

@ -1,7 +1,6 @@
package com.yipin.liuwanr.service; package com.yipin.liuwanr.service;
import com.aliyun.oss.OSSClient; import com.aliyun.oss.OSSClient;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.yipin.liuwanr.AliyunOssConfig; import com.yipin.liuwanr.AliyunOssConfig;
@ -12,8 +11,8 @@ import com.yipin.liuwanr.mapper.OrganizationRelationshipMapper;
import com.yipin.liuwanr.mapper.StaffMapper; import com.yipin.liuwanr.mapper.StaffMapper;
import com.yipin.liuwanr.mapper.StudentMapper; import com.yipin.liuwanr.mapper.StudentMapper;
import com.yipin.liuwanr.mapper.UserInfoMapper; import com.yipin.liuwanr.mapper.UserInfoMapper;
import com.yipin.liuwanr.util.MD5;
import com.yipin.liuwanr.vo.UserInfoReceiveVo; import com.yipin.liuwanr.vo.UserInfoReceiveVo;
import org.apache.poi.ss.formula.functions.T;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -26,7 +25,10 @@ import redis.clients.jedis.JedisCluster;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -426,10 +428,11 @@ public class UserInfoService {
//区分密码大小写 //区分密码大小写
boolean num = false; boolean num = false;
if (user != null){ if (user != null){
num = password.equals(user.getPassword()); //校验密码
num = MD5.encrypt(password).equals(user.getPassword());
} }
if(user!=null && num == true) { if(user!=null && num) {
Integer userId = user.getUserId(); Integer userId = user.getUserId();
List<UserInfo> staffList = userInfoMapper.loginsGetStaffSchoolInfo(userId,schoolId); List<UserInfo> staffList = userInfoMapper.loginsGetStaffSchoolInfo(userId,schoolId);

@ -0,0 +1,31 @@
package com.yipin.liuwanr.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public final class MD5 {
public static String encrypt(String strSrc) {
try {
char hexChars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'a', 'b', 'c', 'd', 'e', 'f' };
byte[] bytes = strSrc.getBytes();
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(bytes);
bytes = md.digest();
int j = bytes.length;
char[] chars = new char[j * 2];
int k = 0;
for (int i = 0; i < bytes.length; i++) {
byte b = bytes[i];
chars[k++] = hexChars[b >>> 4 & 0xf];
chars[k++] = hexChars[b & 0xf];
}
return new String(chars);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
throw new RuntimeException("MD5加密出错!!+" + e);
}
}
}
Loading…
Cancel
Save