3-30.BOS项目-登录功能-MD5登录讲解

 

 

UserServiceImpl

    @Override
    public User login(String username, String password) {
        return userDao.find(username, MD5Utils.text2md5(password));
    }

 

 

 

MD5Utils

package com.gyf.bos.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Utils {
    public static String text2md5(String text) {

        try {
            MessageDigest digest = MessageDigest.getInstance("md5");
            byte[] bs = digest.digest(text.getBytes());
            String hexString = "";
            for (byte b : bs) {
                int temp = b & 255;
                if (temp < 16 && temp >= 0) {
                    hexString = hexString + "0" + Integer.toHexString(temp);
                } else {
                    hexString = hexString + Integer.toHexString(temp);
                }
            }
            return hexString;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";

    }
}

 

posted @ 2019-05-26 01:19  expworld  阅读(88)  评论(0)    收藏  举报