Search in sources :

Example 1 with Md5Hash

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);
}
Also used : SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) ByteSource(org.apache.shiro.util.ByteSource) Md5Hash(org.apache.shiro.crypto.hash.Md5Hash)

Example 2 with Md5Hash

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();
}
Also used : IncorrectCredentialsException(org.apache.shiro.authc.IncorrectCredentialsException) JSONObject(com.alibaba.fastjson.JSONObject) AuthenticationException(org.apache.shiro.authc.AuthenticationException) Md5Hash(org.apache.shiro.crypto.hash.Md5Hash) Subject(org.apache.shiro.subject.Subject) AuthenticationException(org.apache.shiro.authc.AuthenticationException) IncorrectCredentialsException(org.apache.shiro.authc.IncorrectCredentialsException) LockedAccountException(org.apache.shiro.authc.LockedAccountException) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Md5Hash (org.apache.shiro.crypto.hash.Md5Hash)2 JSONObject (com.alibaba.fastjson.JSONObject)1 AuthenticationException (org.apache.shiro.authc.AuthenticationException)1 IncorrectCredentialsException (org.apache.shiro.authc.IncorrectCredentialsException)1 LockedAccountException (org.apache.shiro.authc.LockedAccountException)1 SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1 Subject (org.apache.shiro.subject.Subject)1 ByteSource (org.apache.shiro.util.ByteSource)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1