第一小问就是判断账号或密码是否为空,第二小问就是用md5对密码进行加密,或者aes加密。第三小问就有点广了。
a.判断 密码账号不为空 不为空串/去数据库查询的结果不为空
b.MD5加密存入数据库,记得查询时也要进行调用
package com.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Util {
// 静态方法,便于作为工具类
/**
* @param password
* 加密的字符串
* @return 加密后的字符串
*/
public static String getMd5(Object password) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(((String) password).getBytes());
byte b[] = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
// 32位加密
return buf.toString();
// 16位的加密
// return buf.toString().substring(8, 24);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
/*
* public static void main(String[] args) { // 测试
* System.out.println(MD5Util.getMd5("123456789")); }
*/
}