use of org.apache.shiro.crypto.hash.Md5Hash in project vip by guangdada.
the class ShiroFactroy method info.
@Override
public SimpleAuthenticationInfo info(ShiroUser shiroUser, User user, String realmName) {
String credentials = user.getPassword();
// 密码加盐处理
String source = user.getSalt();
ByteSource credentialsSalt = new Md5Hash(source);
return new SimpleAuthenticationInfo(shiroUser, credentials, credentialsSalt, realmName);
}
use of org.apache.shiro.crypto.hash.Md5Hash in project springBoot-learn-demo by nbfujx.
the class LoginControllerImpl method ajaxLogin.
/**
* 登录方法
* @param name
* @param password
* @return
*/
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public String ajaxLogin(String name, String password) {
JSONObject jsonObject = new JSONObject();
Subject subject = SecurityUtils.getSubject();
String passwordmd5 = new Md5Hash(password, "2").toString();
UsernamePasswordToken token = new UsernamePasswordToken(name, passwordmd5);
try {
subject.login(token);
jsonObject.put("token", subject.getSession().getId());
jsonObject.put("msg", "登录成功");
} catch (IncorrectCredentialsException e) {
jsonObject.put("msg", "密码错误");
} catch (AuthenticationException e) {
jsonObject.put("msg", "该用户不存在");
} catch (Exception e) {
e.printStackTrace();
}
return jsonObject.toString();
}
Aggregations