Example usage for org.apache.shiro.authc.credential PasswordService passwordsMatch

List of usage examples for org.apache.shiro.authc.credential PasswordService passwordsMatch

Introduction

In this page you can find the example usage for org.apache.shiro.authc.credential PasswordService passwordsMatch.

Prototype

boolean passwordsMatch(Object submittedPlaintext, String encrypted);

Source Link

Document

Returns true if the submittedPlaintext password matches the existing saved password, false otherwise.

Usage

From source file:com.lzs.core.support.ShiroDbRealm.java

License:Apache License

/**
 * ?,./*from   w  w w.j  a va 2s.c  o m*/
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
        throws AuthenticationException {
    try {
        UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
        String userName = token.getUsername();
        String plainPassword = String.valueOf(token.getPassword());
        if (userName != null && !"".equals(userName)) {
            User user = userService.findUniqueBy("username", token.getUsername());
            if (user == null || user.getDeleted() == 1) {
                throw new NoResultException("??");
            }
            PasswordService passwordService = new DefaultPasswordService();
            if (passwordService.passwordsMatch(plainPassword, user.getPassword())) {
                return new SimpleAuthenticationInfo(new ShiroUser(user.getId(), user.getUsername()),
                        plainPassword, getName());
            }
        }
    } catch (NoResultException e) {
        RuntimeException re = new RuntimeException("??", e);
        logger.error(re.getMessage(), re);
        throw re;
    } catch (NonUniqueResultException e) {
        RuntimeException re = new RuntimeException("????", e);
        logger.error(re.getMessage(), re);
        throw re;
    } catch (Exception e) {
        logger.error("", e);
    }

    throw new RuntimeException("??");
}

From source file:com.mycompany.newplease.RegisterBean.java

public void doRegister() throws SQLException {
    PasswordService dps = new DefaultPasswordService();
    System.out.println("Test succesful");
    //con = ds.getConnection();
    //PreparedStatement ps = con.prepareStatement("insert into user(username, password, email, fullname) values (?, ?, ?, ?)");
    String pass = "333";
    String temp = dps.encryptPassword(pass);
    //ps.setString(1, userName);
    //ps.setString(2, temp);
    //ps.setString(3, emailAddress);
    //ps.setString(4, "Salih ERKC");
    //ps.executeUpdate();
    //DatabaseOperations.initializeDB(this);
    System.out.println("AAAA  " + dps.passwordsMatch(pass, temp));

}