import sun.security.provider.MD5;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
* @author ray.zhangr
* @date 2020/8/26 1:47 下午
*/
public class TestPasswd {
* 模拟用户提交登陆密码校验
* 明文密码在网络中传输使用https
* 如果使用http需要自己实现加密传输
* @param userId
* @param password
* @param passwdEncrypt
* @return
*/
private static Boolean checkPW(String userId, String password, String passwdEncrypt) {
String salt = userId;
String passwdVerify = Md5Util.md5(userId + password);
return passwdVerify.equals(passwdEncrypt);
}
public static void main(String args[]) {
System.out.println(checkPW("64359", "HappyGeekTime", "70970617f196ec4102cc396db5b06bcf"));
}
}
* MD5工具类
* 转自https://www.cnblogs.com/huxiaoguang/articles/10809750.html
*/
class Md5Util {
public static String md5(String buffer)
{
String string = null;
char hexDigist[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
MessageDigest md;
try {
md = MessageDigest.getInstance("MD5");
md.update(buffer.getBytes());
byte[] datas = md.digest();
char[] str = new char[2*16];
int k = 0;
for(int i=0;i<16;i++)
{
byte b = datas[i];
str[k++] = hexDigist[b>>>4 & 0xf];
str[k++] = hexDigist[b & 0xf];
}
string = new String(str);
} catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
return string;
}
}
评论