cn.hutool hutool-all 5.8.15
@Override public String login(LoginParam loginParam) { User user = userDAO.selectByName(loginParam.getUsername()); if (user == null) { throw new CommonException("用户名错误"); } // hutool提供的加解密的工具类 String md5Pwd = SecureUtil.md5(loginParam.getPassword()); if (!md5Pwd.equals(user.getPassword())) { throw new CommonException("密码错误"); } Mapmap = new HashMap<>(); map.put("uid", user.getId()); // 使用jwt做token,一般需要将jwt作为key存到redis中 // jwt已经存了用户信息,jwt可以设置过期时间,实现之前redis存储登录信息的功能 String jwt = JwtUtils.createJwt(map); return jwt; }
数据库处理
select md5('123456')