Posted on 2011-05-11 15:46
MyOracleX 阅读(147)
评论(0) 编辑 收藏
创建用户: public Long createTempUser(TempUser user) {
TempUser tempuser = this.findTempUserByName(user.getYhm());
user.setMm(createEncryptPSW(user.getMm().trim())); //生成加密密码
if (tempuser != null) {
user.setId(tempuser.getId());
this.getHibernateTemplate().merge(user);
} else {
this.getHibernateTemplate().saveOrUpdate(user);
}
return user.getId();
}
createEncryptPSW(加密方法): private String createEncryptPSW(String psw) {
MessageDigest messagedigest;
try {
messagedigest = MessageDigest.getInstance("MD5");
messagedigest.update(psw.getBytes("UTF8"));
byte abyte0[] = messagedigest.digest();
return (new BASE64Encoder()).encode(abyte0);
} catch (Exception e) {
throw new RuntimeException("加密失败:" + e.getMessage());
}
}
登录(解密):
public Long userCer(String userName, String password) {
TempUser user = this.findTempUserByName(userName);
if (null == user) return 0L;
boolean flag = createEncryptPSW(password.trim()).equals(user.getMm());
if (flag) return user.getId();
return 0L;
}