springboot 用springsecurity来登录,重写密码加密用md5的加密方法

时间:2024-10-14 19:05:21
@Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        (customUserService()).passwordEncoder(new PasswordEncoder(){
            @Override
            public String encode(CharSequence rawPassword) {
                return ((String)rawPassword);
            }
 
            @Override
            public boolean matches(CharSequence rawPassword, String encodedPassword) {//rawPassword用户输入的,encodedPassword数据库查出来的
                return (((String)rawPassword));
            }}); 

    }
 
添加MD5工具类

 
import ;
/**
 * MD5加密工具
 *
 */
public class MD5Util {
 
    private static final String SALT = "tamboo";
 
    public static String encode(String password) {
        password = password + SALT;
        MessageDigest md5 = null;
        try {
            md5 = ("MD5");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        char[] charArray = ();
        byte[] byteArray = new byte[];
 
        for (int i = 0; i < ; i++)
            byteArray[i] = (byte) charArray[i];
        byte[] md5Bytes = (byteArray);
        StringBuffer hexValue = new StringBuffer();
        for (int i = 0; i < ; i++) {
            int val = ((int) md5Bytes[i]) & 0xff;
            if (val < 16) {
                ("0");
            }
 
            ((val));
        }
        return ();
    }
 
    public static void main(String[] args) {
        (("abel"));
 
 
    }
}