PasswordResetModel::validatePasswordChange PHP 메소드

validatePasswordChange() 공개 정적인 메소드

Validates current and new passwords
public static validatePasswordChange ( string $user_name, string $user_password_current, string $user_password_new, string $user_password_repeat ) : boolean
$user_name string
$user_password_current string
$user_password_new string
$user_password_repeat string
리턴 boolean
    public static function validatePasswordChange($user_name, $user_password_current, $user_password_new, $user_password_repeat)
    {
        $database = DatabaseFactory::getFactory()->getConnection();
        $sql = "SELECT user_password_hash, user_failed_logins FROM users WHERE user_name = :user_name LIMIT 1;";
        $query = $database->prepare($sql);
        $query->execute(array(':user_name' => $user_name));
        $user = $query->fetch();
        if ($query->rowCount() == 1) {
            $user_password_hash = $user->user_password_hash;
        } else {
            Session::add('feedback_negative', Text::get('FEEDBACK_USER_DOES_NOT_EXIST'));
            return false;
        }
        if (!password_verify($user_password_current, $user_password_hash)) {
            Session::add('feedback_negative', Text::get('FEEDBACK_PASSWORD_CURRENT_INCORRECT'));
            return false;
        } else {
            if (empty($user_password_new) || empty($user_password_repeat)) {
                Session::add('feedback_negative', Text::get('FEEDBACK_PASSWORD_FIELD_EMPTY'));
                return false;
            } else {
                if ($user_password_new !== $user_password_repeat) {
                    Session::add('feedback_negative', Text::get('FEEDBACK_PASSWORD_REPEAT_WRONG'));
                    return false;
                } else {
                    if (strlen($user_password_new) < 6) {
                        Session::add('feedback_negative', Text::get('FEEDBACK_PASSWORD_TOO_SHORT'));
                        return false;
                    } else {
                        if ($user_password_current == $user_password_new) {
                            Session::add('feedback_negative', Text::get('FEEDBACK_PASSWORD_NEW_SAME_AS_CURRENT'));
                            return false;
                        }
                    }
                }
            }
        }
        return true;
    }