Package org.encuestame.core.security.util

Source Code of org.encuestame.core.security.util.EnMePasswordUtils

/*
************************************************************************************
* Copyright (C) 2001-2009 encuestame: system online surveys Copyright (C) 2011
* encuestame Development Team.
* Licensed under the Apache Software License version 2.0
* 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.encuestame.core.security.util;

import org.jasypt.util.password.StrongPasswordEncryptor;

/**
* Password Utils.
* @author Picado, Juan juanATencuestame.org
* @since 19/12/2009 22:37:32
* @version $Id$
*/
public class EnMePasswordUtils {

    /**
     * Default lenght password.
     */
    public static final Integer DEFAULT_LENGTH_PASSWORD = 8;

    /**
     * Create Random Password.
     * @param length
     * @return
     */
    public static final String createRandomPassword(final int length){
        return PasswordGenerator.getPassword(length);
    }

    /**
     * Encrypt the password.
     * @param password password
     * @return password encrypt
     */
    public static final String encryptPassworD(final String password) {
        final StrongPasswordEncryptor passwordEncryptor = new StrongPasswordEncryptor();
        return passwordEncryptor.encryptPassword(password);
    }


    /**
     * Check if password is correct.
     * @param inputPassword input password
     * @param encryptedPassword encrypted password
     * @return if correct true and if not false
     */
    public static final Boolean checkPassword(final String inputPassword, final String encryptedPassword ){
        final StrongPasswordEncryptor passwordEncryptor = new StrongPasswordEncryptor();
        if (passwordEncryptor.checkPassword(inputPassword, encryptedPassword)) {
            // correct
            return true;
          } else {
            // bad password
            return false;
          }
    }
}
TOP

Related Classes of org.encuestame.core.security.util.EnMePasswordUtils

TOP
Copyright © 2018 www.massapi.com. 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.