src/main/java/com/moral/monitor/service/LoginService.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/monitor/util/Crypto.java | ●●●●● patch | view | raw | blame | history |
src/main/java/com/moral/monitor/service/LoginService.java
@@ -2,6 +2,7 @@ import com.moral.monitor.dao.LoginDao; import com.moral.monitor.entity.Account; import com.moral.monitor.util.Crypto; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -14,6 +15,6 @@ @Resource LoginDao loginDao; public Account login(String account, String password){ return loginDao.login(account,password); return loginDao.login(account, Crypto.md5(password)); } } src/main/java/com/moral/monitor/util/Crypto.java
New file @@ -0,0 +1,32 @@ package com.moral.monitor.util; import sun.misc.BASE64Encoder; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Crypto { /**利用MD5进行加密 * @param str 待加密的字符串 * @return 加密后的字符串 * @throws NoSuchAlgorithmException 没有这种产生消息摘要的算法 * @throws UnsupportedEncodingException */ public static String md5(String str) { String newstr = ""; try { //确定计算方法 MessageDigest md5 = MessageDigest.getInstance("MD5"); BASE64Encoder base64en = new BASE64Encoder(); //加密后的字符串 newstr = base64en.encode(md5.digest(str.getBytes("utf-8"))); } catch (NoSuchAlgorithmException e1) { e1.printStackTrace(); } catch (UnsupportedEncodingException e2) { e2.printStackTrace(); } return newstr; } }