Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * =============================================================================
  * 
  *   Copyright (c) 2007, The JASYPT team (http://www.jasypt.org)
  * 
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   you may not use this file except in compliance with the License.
  *   You may obtain a copy of the License at
  * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * 
 * =============================================================================
 */
package org.jasypt.util.password;

Utility class for easily performing password digesting and checking.

This class internally holds a org.jasypt.digest.StandardStringDigester configured this way:

  • Algorithm: MD5.
  • Salt size: 8 bytes.
  • Iterations: 1000.

The required steps to use it are:

  1. Create an instance (using new).
  2. Perform the desired encryptPassword(java.lang.String) or checkPassword(java.lang.String,java.lang.String) operations.

This class is thread-safe

Author(s):
Daniel Fernández Garrido
Since:
1.2 (class existed as org.jasypt.util.PasswordEncryptor since 1.0)
public final class BasicPasswordEncryptor implements PasswordEncryptor {
    // The internal digester used
    private StandardStringDigester digester = null;
    
    
    
Creates a new instance of BasicPasswordEncryptor
    public BasicPasswordEncryptor() {
        super();
        this. = new StandardStringDigester();
        this..initialize();
    }
    
    
    
Encrypts (digests) a password.

Parameters:
password the password to be encrypted.
Returns:
the resulting digest.
See also:
org.jasypt.digest.StandardStringDigester.digest(java.lang.String)
    public String encryptPassword(String password) {
        return .digest(password);
    }

    
    
Checks an unencrypted (plain) password against an encrypted one (a digest) to see if they match.

Parameters:
plainPassword the plain password to check.
encryptedPassword the digest against which to check the password.
Returns:
true if passwords match, false if not.
See also:
org.jasypt.digest.StandardStringDigester.matches(java.lang.String,java.lang.String)
    public boolean checkPassword(String plainPassword
            String encryptedPassword) {
        return .matches(plainPasswordencryptedPassword);
    }
    
New to GrepCode? Check out our FAQ X