发表于: 2017-10-28 23:48:06
1 833
今天完成的事情.
完成Des加密,
在输入用户密码之后对密码进行des加密,然后与数据库里面账号密码进行对比.
@RequestMapping(value = "/u/first", method = RequestMethod.POST)
public String countRegist(HttpServletResponse httpServletResponse, HttpServletRequest httpServletRequest, Model model, String userName,
String userPassword) {
try {
System.out.println("user name" +userName);
System.out.println("userPassword" + userPassword);
Integer i = registService.countRegist(desUtil.encrypt(userName),desUtil.encrypt(userPassword));
System.out.println(desUtil.encrypt(userName));
System.out.println(desUtil.encrypt(userPassword));
System.out.println(i);
loggerController.info("匹配信息" + i);
if (i == 1) {
Cookie cookie = new Cookie(userName.trim(), userPassword.trim());
cookie.setMaxAge(60 * 60 * 24 * 7);
cookie.setPath("/");
httpServletResponse.addCookie(cookie);
model.addAttribute("userName", userName);
model.addAttribute("userPassword", userPassword);
return "/home/home";
} else {
return "/regist/regist";
}
} catch (Exception e) {
e.printStackTrace();
loggerController.error(e.getMessage());
return "common/errorJson";
}
}
完成MD5对Cookie的加密
if (i == 1) {
Cookie cookie = new Cookie(md5Util.getMd5(userName), md5Util.getMd5(userPassword));
cookie.setMaxAge(60 * 60 * 24 * 7);
cookie.setPath("/");
httpServletResponse.addCookie(cookie);
model.addAttribute("userName", md5Util.getMd5(userName));
model.addAttribute("userPassword", md5Util.getMd5(userPassword));
return "/home/home";
} else {
return "/regist/regist";
明天计划完成的事情:
准备小课堂.
学习使用拦截器.
遇到的困难 :
参考网上Des和Md5工具类,写demo, 发现我的工具类只可以输入8位数以上的密码.
和师兄的做比较尝试各种方法不行,无奈换了个工具类,
第二个问题比较基础的问题,报错空指针,值无法传递,,最后发现是我只声明了这个工具类而没有实例化,只有实例化之后才可以调用其中的方法.
收获:
DES:算法DES要求密钥长度为64位密钥, 有效密钥56位。64bits=8*8*1,即8个ascii字符。 不够的话我们可以自动补位
DESede:算法DESede要求的密钥位数为192位,即192bits=64*3=8*8*3,即24个ascii字符。
解决问题思路很重要,从报错地方开始出参入参都打印参数,然后逐个排除,在方法里面打印参数.这是迅速解决问题的方法.
任务开始时间2017-10-23
任务结束时间2017-11-05
无延期风险.
禅道;http://task.ptteng.com/zentao/task-view-12682.html
评论