Calculates and returns Score for the Strength of a Password (max 56).
@access		public
@static
@param		string		$password
@return		int			between -300 and +56
976197
public static function getScore( $password )
	{
		$score	= 0;

		//  --  LENGTH  --  //
		$length	= strlen( $password );
		$min	= self::$minLength;
		if( $length < $min )															// Password too short
			$score	-= 100;
		else if( $length >= $min && $length <= $min + 2 ) 								// Password Short
			$score += 6;
		else if( $length >= $min + 3 && $length <= $min + 4 )							// Password Medium
			$score += 12;
		else if( $length >= $min + 5 )													// Password Large
			$score += 18;

		//  --  CASE SENSE  --  //
		if( preg_match( "/[a-z]/", $password ) )										// at least one lower case letter
			$score	+= 1;
		if( preg_match( "/[A-Z]/", $password ) )										// at least one upper case letter
			$score	+= 5;

		//  --  NUMBERS  --  //
		if( preg_match( "/\d+/", $password ) )											// at least one number
			$score	+= 5;
		if( preg_match( "/(.*[0-9].*[0-9].*[0-9])/", $password ) )						// at least three numbers
			$score	+= 7;

		//  --  SPECIAL CHARACTERS  --  //
		if( preg_match( "/.[!,@,#,$,%,^,&,*,?,_,~]/", $password ) )						// at least one special character
			$score	+= 5;
		if( preg_match( "/(.*[!@#$%^&*?_~].*[!@#$%^&*?_~])/", $password ) )				// at least two special characters
			$score	+= 7;

		//  --  COMBINATION  --  //
		if( preg_match( "/([a-z].*[A-Z])|([A-Z].*[a-z])/", $password ) )				// both upper and lower case
			$score	+= 2;
		if( preg_match( "/[a-z]/i", $password ) && preg_match( "/\d/", $password ) )	// both letters and numbers
			$score	+= 3;
		$regEx	= "/([a-z0-9].*[!@#$%^&*?_~])|([!@#$%^&*?_~].*[a-z0-9])/i";
		if( preg_match( $regEx, $password ) )											// letters, numbers, and special characters
			$score	+= 3;

		//  --  BAD WORDS  --  //
		if( in_array( strtolower( $password ), self::$badWords ) ) 
			$score -= 200;
		return $score;
	}
1125437
public function validatePassword(string $password): bool
    {
        return \Yii::$app->security->validatePassword($password, $this->password_hash);
    }
49945
public function validate(string $password): bool
    {
        foreach ($this->validators as $validator) {
            $validator->validate($password);
        }

        return true;
    }
1023178
public function salt($password, $member = null)
    {
        $generator = new RandomGenerator();
        return sprintf('%02d', self::$cost) . '$' . substr($generator->randomToken('sha1'), 0, 22);
    }
1319934
public static function verifyPassword(string $password, string $hash)
    {
        if (\password_verify($password, $hash)) {
            if (\password_needs_rehash($hash, \PASSWORD_DEFAULT)) {
                return self::password($password);
            }

            return true;
        }

        return false;
    }
161110
public static function cryptHash($password)
    {
        $salt = substr(base64_encode(chr(mt_rand(0, 255))), 0, 2);
        $salt = str_replace('+', '.', $salt);
        return crypt($password, $salt);
    }
562969
public static function validate($password, $hash) {
        $params = explode(":", $hash);
        if (count($params) < 4)
            return false;
        $pbkdf2 = base64_decode($params[self::$hash_pbkdf2_index]);
        return self::slowEquals(
                $pbkdf2, self::calculate(
                    $params[self::$hash_alogrithm_index], $password, $params[self::$hash_salt_index], (int) $params[self::$hash_iteration_index], strlen($pbkdf2), true
                )
        );
    }
1362940
function checkPassword($password)
    {
        if ($this->password == '') {
            return false;
        }
        list ($algo, $salt, $hash) = explode(':', $this->password);
        if ($hash == $algo($salt . $password)) {
            return true;
        } else {
            return false;
        }
    }
1103639
public function checkPassword($password)
    {
        $valid = static::$dispatcher->until(new CheckingPassword($this, $password));

        if ($valid !== null) {
            return $valid;
        }

        return static::$hasher->check($password, $this->password);
    }
1279584
public function verify($password): bool {
        if ($password instanceof StringClass || $password instanceof PasswordClass) {
            return password_verify($password->getValue(), $this->getValue());
        }
        return password_verify($password, $this->getValue());
    }
1333754
public function lmPasswordHash($password = null)
    {
        $plain = isset($password) ? $password : $this->password;

        $plain = substr(strtoupper($plain), 0, 14);
        while (strlen($plain) < 14) {
             $plain .= "\0";
        }

        return $this->_desHash(substr($plain, 0, 7)) . $this->_desHash(substr($plain, 7, 7));
    }
1339623
private function hashModeBcrypt($password)
    {
        $this->cwsDebug->titleH2('Create password hash using BCRYPT');
        $this->cwsDebug->labelValue('Password', $password);

        $ite = rand(self::BCRYPT_MIN_ITE, self::BCRYPT_MAX_ITE);
        $this->cwsDebug->labelValue('Iterations', $ite);

        $salt = $this->getBlowfishSalt($ite);
        $this->cwsDebug->labelValue('Salt', $salt);

        $hash = crypt($password, $salt);
        $this->cwsDebug->labelValue('Hash', $hash);
        $this->cwsDebug->labelValue('Length', strlen($hash));

        if (CRYPT_BLOWFISH == 1 && strlen($hash) == self::BCRYPT_LENGTH) {
            return $hash;
        }

        $this->error = 'Cannot generate the BCRYPT password hash...';
        $this->cwsDebug->error($this->error);
    }
869119
public static function verify($password, $hash): int
    {
        // Fail if hash doesn't match
        if (!$password || !$hash || !password_verify($password, $hash)) {
            return 0;
        }

        // Otherwise check if hash needs an update.
        return password_needs_rehash($hash, PASSWORD_DEFAULT) ? 2 : 1;
    }
1043867
public function passwordNeedRehash(string $password) : bool
    {
        $options = [
            //'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM), // Never use a static salt or one that is not randomly generated.
            'cost' => 12, // the default cost is 10
        ];

        if (password_needs_rehash($this->password, PASSWORD_DEFAULT, $options)) {
            $this->password = self::passwordHash($password);
            $this->update();

            return true;
        }

        return false;
    }
255261
public function encodePassword($password)
    {
        $password = '"'.$password.'"';

        $encoded = '';

        $length = strlen($password);

        for ($i = 0; $i < $length; $i++) {
            $encoded .= "{$password{$i}
            }\000";
        }

        return $encoded;
    }
63537
public function authenticate(string $password): bool
    {
        $hash = $this->get('hashed_password');

        $isHashed = null !== $hash;
        if (!$isHashed) {
            // If there is no hashed password, fake verify with default hash.
            $hash = Grav::instance()['config']->get('system.security.default_hash');
        }

        // Always execute verify() to protect us from timing attacks, but make the test to fail if hashed password wasn't set.
        $result = Authentication::verify($password, $hash) && $isHashed;

        $plaintext_password = $this->get('password');
        if (null !== $plaintext_password) {
            // Plain-text password is still stored, check if it matches.
            if ($password !== $plaintext_password) {
                return false;
            }

            // Force hash update to get rid of plaintext password.
            $result = 2;
        }

        if ($result === 2) {
            // Password needs to be updated, save the user.
            $this->set('password', $password);
            $this->undef('hashed_password');
            $this->save();
        }

        return (bool)$result;
    }
1133015
public function actionValidatePassword($user, $password)
    {
        $user = $this->getUser($user);
        $result = $user->validatePassword($password);
        if ($result) {
            echo "Correct.\n";
        } else {
            echo "Incorrect.\n";
        }
        return static::EXIT_CODE_NORMAL;
    }