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

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

Introduction

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

Prototype

String encryptPassword(Object plaintextPassword) throws IllegalArgumentException;

Source Link

Document

Converts the specified plaintext password (usually acquired from your application's 'new user' or 'password reset' workflow) into a formatted string safe for storage.

Usage

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));

}

From source file:net.agetsuma.sample.shiro.rest.contoller.UserAccountResource.java

@Path("sign_up")
@POST/*from  w ww. ja v a 2  s .c  om*/
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Message signUp(@Valid @BeanParam SignUpForm form) {
    //        PasswordService ps = new DefaultPasswordService();

    PasswordService ps = new BCryptPasswordService();
    // if you will more strongly, can set logRounds.
    // default rounds is 10.
    //        PasswordService ps = new BCryptPasswordService(12);

    String encryptedPassword = ps.encryptPassword(form.getPassword());

    UserAccount newAccount = new UserAccount(form.getEmail(), encryptedPassword, form.getFirstName(),
            form.getLastName(), Role.valueOf(form.getRole()));

    userAccountRepository.create(newAccount);
    return Messages.thanksForSignUp(newAccount.getEmail());
}

From source file:org.jlgranda.fede.controller.SubjectHome.java

License:Open Source License

public static void main(String[] args) {

    PasswordService svc = new DefaultPasswordService();

    //RandomNumberGenerator rng = new SecureRandomNumberGenerator();
    //Object salt = rng.nextBytes();

    // Now hash the plain-text password with the random salt and multiple
    // iterations and then Base64-encode the value (requires less space than Hex):
    //String hashedPasswordBase64 = new Sha256Hash("sin password", salt, 1024).toBase64();

    //System.out.println("hashedPasswordBase64: " + hashedPasswordBase64);
    //System.out.println("sal: " + salt.toString());
    System.out.println("sv: " + svc.encryptPassword("1104499049"));
    //user.setSalt(salt.toString());
}