Example usage for org.springframework.security.crypto.bcrypt BCrypt gensalt

List of usage examples for org.springframework.security.crypto.bcrypt BCrypt gensalt

Introduction

In this page you can find the example usage for org.springframework.security.crypto.bcrypt BCrypt gensalt.

Prototype

public static String gensalt(String prefix, int log_rounds, SecureRandom random)
        throws IllegalArgumentException 

Source Link

Document

Generate a salt for use with the BCrypt.hashpw() method

Usage

From source file:org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder.java

public String encode(CharSequence rawPassword) {
    String salt;//from   w w  w.  ja va2s . c o  m
    if (strength > 0) {
        if (random != null) {
            salt = BCrypt.gensalt(version.getVersion(), strength, random);
        } else {
            salt = BCrypt.gensalt(version.getVersion(), strength);
        }
    } else {
        salt = BCrypt.gensalt(version.getVersion());
    }
    return BCrypt.hashpw(rawPassword.toString(), salt);
}