Package org.apache.shiro.crypto.hash

Examples of org.apache.shiro.crypto.hash.Sha256Hash


  public void createUser(String username, String email, String password) {
    User user = new User();
    user.setUsername(username);
    user.setEmail(email);
    user.setPassword(new Sha256Hash(password).toHex());
    userDAO.createUser(user);
  }
View Full Code Here


import org.springframework.util.StringUtils;

public final class SecurityUtil {

    public static String passwordEncrypt(String password) {
        return new Sha256Hash(password).toBase64();
    }
View Full Code Here

        // we also use a user agent as a validation factor
        // so when we later validate the token, we also validate the user agent
        String secret = generateRandomString();
        String salt = secret.concat(randomNumber.toString());
        return new Sha256Hash(secret, salt, 1024).toBase64();
    }
View Full Code Here

            userManager.create(newUser);

            RandomNumberGenerator numberGenerator = new SecureRandomNumberGenerator();
            ByteSource salt = numberGenerator.nextBytes();

            String hashedPassword = new Sha256Hash("haxx", salt, 1024).toBase64();

            Password newPassword = new Password(newUser.getId(), hashedPassword, salt.getBytes());

            passwordManager.create(newPassword);
View Full Code Here

        int i = 0;
        for (FireUser user : users) {
            passwords.add(
                    new Password(
                    user.getId(),
                    new Sha256Hash(passwordStrs.get(i),
                    ByteSource.Util.bytes(new byte[]{7}), 1024).toBase64(),
                    new byte[]{7}));
            i++;
        }
    }
View Full Code Here

        /*
         * Create a salt, and use it to create a hashed password for the user.
         * Finally, store the hashed password and its salt in the database.
         */
        ByteSource salt = new SecureRandomNumberGenerator().nextBytes();
        String hashedPassword = new Sha256Hash(password, salt, 1024).toBase64();

        Password newPassword = new Password(userID, hashedPassword, salt.getBytes());

        return newPassword;
    }
View Full Code Here

        //password is 'user1' SHA hashed and base64 encoded:
        //The first argument to the hash constructor is the actual value to be hased.  The 2nd is the
        //salt.  In this simple demo scenario, the username and the password are the same, but to clarify the
        //distinction, you would see this in practice:
        //new Sha256Hash( <password>, <cryptographically strong randomly generated salt> (not the username!) )
        String query = "insert into users values ('user1', '" + new Sha256Hash("user1", "user1").toBase64() + "' )";
        jdbcTemplate.execute(query);
        log.debug("Created user1.");

        //password is 'user2' SHA hashed and base64 encoded:
        query = "insert into users values ( 'user2', '"  + new Sha256Hash("user2", "user2").toBase64() + "' )";
        jdbcTemplate.execute(query);
        log.debug("Created user2.");

        query = "insert into roles values ( 'role1' )";
        jdbcTemplate.execute(query);
View Full Code Here

        JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource);

        jdbcTemplate.execute("insert into roles values (1, 'user', 'The default role given to all users.')");
        jdbcTemplate.execute("insert into roles values (2, 'admin', 'The administrator role only given to site admins')");
        jdbcTemplate.execute("insert into roles_permissions values (2, 'user:*')");
        jdbcTemplate.execute("insert into users(id,username,email,password) values (1, 'admin', 'sample@shiro.apache.org', '" + new Sha256Hash("admin").toHex() + "')");
        jdbcTemplate.execute("insert into users_roles values (1, 2)");


    }
View Full Code Here

    public Class<? extends HashedCredentialsMatcher> getMatcherClass() {
        return Sha256CredentialsMatcher.class;
    }

    public AbstractHash hash(Object credentials) {
        return new Sha256Hash(credentials);
    }
View Full Code Here

        Statement sql = null;
        try {
            conn = ds.getConnection();
            sql = conn.createStatement();
            sql.executeUpdate("create table users (username varchar(20), password varchar(20))");
            Sha256Hash sha256Hash = salted ? new Sha256Hash(plainTextPassword, salt) :
                new Sha256Hash(plainTextPassword);
            String password = sha256Hash.toHex();
            sql.executeUpdate("insert into users values ('" + username + "', '" + password + "')");
        } catch (SQLException ex) {
            Assert.fail("Exception creating test database");
        } finally {
            JdbcUtils.closeStatement(sql);
View Full Code Here

TOP

Related Classes of org.apache.shiro.crypto.hash.Sha256Hash

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.