Example usage for org.apache.shiro.crypto.hash Sha1Hash Sha1Hash

List of usage examples for org.apache.shiro.crypto.hash Sha1Hash Sha1Hash

Introduction

In this page you can find the example usage for org.apache.shiro.crypto.hash Sha1Hash Sha1Hash.

Prototype

public Sha1Hash(Object source, Object salt) 

Source Link

Usage

From source file:de.lemo.apps.entities.User.java

License:Open Source License

public void setPassword(final String newPassword) {
    if (newPassword != null && !newPassword.equals(this.encryptedPassword) && !"".equals(newPassword)) {
        ByteSource saltSource = new SecureRandomNumberGenerator().nextBytes();
        this.passwordSalt = saltSource.getBytes();
        this.encryptedPassword = new Sha1Hash(newPassword, saltSource).toString();
    }//from w  ww  .j ava  2 s . c o  m
}

From source file:de.lemo.apps.entities.User.java

License:Open Source License

public void setPasswordConf(final String newPassword) {
    if (newPassword != null && !newPassword.equals(this.encryptedPassword) && !"".equals(newPassword)) {
        ByteSource saltSource = new SecureRandomNumberGenerator().nextBytes();
        this.passwordSalt = saltSource.getBytes();
        if (this.tempPassword != null
                && this.tempPassword.equals(new Sha1Hash(newPassword, saltSource).toString()))
            this.encryptedPassword = new Sha1Hash(newPassword, saltSource).toString();
        else//from www  .j a v  a 2s  . c o  m
            this.tempPassword = new Sha1Hash(newPassword, saltSource).toString();
    }
}

From source file:de.lemo.apps.entities.User.java

License:Open Source License

@Transient
public Boolean checkPassword(String password) {
    ByteSource saltSource = ByteSource.Util.bytes(this.getPasswordSalt());
    String givenPassword = new Sha1Hash(password, saltSource).toString();
    if (givenPassword != null && givenPassword.equals(this.encryptedPassword)) {
        return true;
    }/*from   w ww. j  a  va 2  s.co  m*/
    return false;
}

From source file:org.smallmind.nutsnbolts.shiro.realm.ActiveDirectoryLdapRealm.java

License:Open Source License

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {

    try {// ww  w .  j  a v a  2s  . c  o m

        SearchControls searchControls;
        NamingEnumeration answer;
        String searchFilter;

        searchFilter = "(&(objectClass=user)(sAMAccountName=" + token.getPrincipal() + "))";

        searchControls = new SearchControls();
        searchControls.setReturningAttributes(RETURNED_ATTRIBUTES);
        searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        searchControls.setCountLimit(1);

        answer = getLdapContext(connectionDetails.getUserName(), connectionDetails.getPassword())
                .search(searchPath, searchFilter, searchControls);
        if (answer.hasMoreElements()) {
            if (((SearchResult) answer.next()).getAttributes() != null) {
                getLdapContext(token.getPrincipal().toString() + "@" + domain,
                        new String((char[]) token.getCredentials()));

                Hash sha1Hash;
                ByteSource salt;

                sha1Hash = new Sha1Hash(new String((char[]) token.getCredentials()),
                        salt = new SimpleByteSource(UUID.randomUUID().toString()));

                return new SimpleAuthenticationInfo(token.getPrincipal(), sha1Hash.getBytes(), salt, getName());
            }
        }
    } catch (NamingException namingException) {
        throw new AuthenticationException(namingException);
    }

    return null;
}