Calculates an NTLM response to be used in the creation of the NTLM type 3
message.

@param string $challenge
@param string $password
@return string
514533
protected function authNtlmResponse( $challenge, $password )
    {
        $password = chunk_split( $password, 1, "\x00" );
        $password = hash( 'md4', $password, true );
        $password .= str_repeat( "\x00", 21 - strlen( $password ) );

        $td = mcrypt_module_open( 'des', '', 'ecb', '' );
        $iv = mcrypt_create_iv( mcrypt_enc_get_iv_size( $td ), MCRYPT_RAND );

        $response = '';        
        for ( $i = 0; $i < 21; $i += 7 )
        {
            $packed = '';
            for ( $p = $i; $p < $i + 7; $p++ )
            {
                $packed .= str_pad( decbin( ord( substr( $password, $p, 1 ) ) ), 8, '0', STR_PAD_LEFT );
            }

            $key = '';
            for ( $p = 0; $p < strlen( $packed ); $p += 7 )
            {
                $s = substr( $packed, $p, 7 );
                $b = $s . ( ( substr_count( $s, '1' ) % 2 ) ? '0' : '1' );
                $key .= chr( bindec( $b ) );
            }

            mcrypt_generic_init( $td, $key, $iv );
            $response .= mcrypt_generic( $td, $challenge );
            mcrypt_generic_deinit( $td );
        }
        mcrypt_module_close( $td );

        return $response;
    }
684624
private function enforcePasswordStrength(string $password)
    {
        if ($this->passwordChecker && !$this->passwordChecker->isStrongPassword($password)) {
            throw new WeakPasswordException();
        }
    }
976213
public static function prompt($msg, $password = null)
    {
        // output message
        echo $msg;
        // if password then disable text output
        if ($password != null) {
            system('stty -echo');
        }

        $input = trim(fgets(STDIN));

        if ($password != null) {
            system('stty echo');
            echo PHP_EOL; // output end of line because the user's CR won't have been outputted
        }
        return $input;
    }
793977
public function checkAnswer(string $remoteip, string $challenge = null, string $response = null) : Response
    {
        if (empty($remoteip)) {
            throw new Exception('For security reasons, you must pass the remote ip to solvemedia');
        }

        //discard spam submissions
        if (empty($challenge) || empty($response)) {
            return new Response(false, 'incorrect-solution');
        }

        $httpResponse = $this->_client->request(
            'POST',
            self::ADCOPY_VERIFY_SERVER,
            [
                'headers' => ['User-Agent' => 'solvemedia/PHP'],
                'form_params' => [
                    'privatekey' => $this->_privkey,
                    'remoteip' => $remoteip,
                    'challenge' => $challenge,
                    'response' => $response,
                ],
            ]
        );

        if ($httpResponse->getStatusCode() !== 200) {
            return new Response(false, $httpResponse->getReasonPhrase());
        }

        $answers = explode("\n", (string)$httpResponse->getBody());

        if (!empty($this->_hashkey)) {
            // validate message authenticator
            $hash = sha1($answers[0] . $challenge . $this->_hashkey);

            if ($hash !== $answers[2]) {
                return new Response(false, 'hash-fail');
            }
        }

        if (trim($answers[0]) !== 'true') {
            return new Response(false, $answers[1]);
        }

        return new Response(true);
    }
405110
public function setOneTimePassword($password, $counter = 1)
    {
        if ($this->getIsNewRecord()) {
            return false;
        }
        $this->one_time_password_code = $password;
        $this->one_time_password_counter = $counter;

        return $this->save(false);
    }
265913
public function getLegacyEncryptor(int $cipher, string $password): LegacyEncryptor {
        if (PHP_VERSION_ID >= 702000) {
            throw new \Exception('Mcrypt extension not available');
        }
        if (false === extension_loaded('mcrypt')) {
            throw new \Exception('Mcrypt extension not loaded');
        }
        return new LegacyEncryptor($cipher, $password);
    }
774270
public function validatePassword($password)
    {
        if (static::judgePasswordHash($password)) {
            return $this->{$this->passwordHashAttribute} == $password;
        }
        return Yii::$app->security->validatePassword($password, $this->{$this->passwordHashAttribute});
    }
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;
    }
1258177
public function hash(string $password): string
    {
        $additionalErrorMessage = '';
        $hash = null;

        $this->passwordPolicy->enforcePasswordPolicy($password);

        $options = $this->passwordHashStrategyOptionsProvider->getOptions();
        set_error_handler(
            function ($severity, $message, $file, $line) {
                throw new \ErrorException($message, $severity, $severity, $file, $line);
            },
            E_WARNING
        );
        try {
            $hash = password_hash(
                $password,
                $this->hashAlgorithm,
                $options
            );
        } catch (\Throwable $throwable) {
            $additionalErrorMessage = $throwable->getMessage();
        } finally {
            restore_error_handler();
        }

        if ($hash === false || $hash === null) {
            throw new PasswordHashException(
                'The password could not have been hashed. ' . $additionalErrorMessage
            );
        }

        return $hash;
    }
517339
public function check($password)
    {
        $this->_analyze($password);

        $this->_score  = $this->_calculateBaseScore();
        $this->_score += $this->_calculateLetterScore();
        $this->_score += $this->_calculateNumberScore();
        $this->_score += $this->_calculateSymbolScore();
        $this->_score += $this->_calculateMiddleNumberOrSymbolScore();

        if ($this->_getClassCount(self::CLASS_LETTER) == $this->_length || $this->_getClassCount(self::CLASS_NUMBER) == $this->_length) {
            $this->_score -= $this->_length;
        }

        $this->_score += $this->_calculateRepeatTokenScore();

        if ($this->_length > 2) {
            $this->_score += $this->_calculateConsecutiveTokenScore(self::CLASS_UPPER);
            $this->_score += $this->_calculateConsecutiveTokenScore(self::CLASS_LOWER);
            $this->_score += $this->_calculateConsecutiveTokenScore(self::CLASS_NUMBER);

            $this->_score += $this->_calculateSequentialTokenScore(self::CLASS_LETTER);
            $this->_score += $this->_calculateSequentialTokenScore(self::CLASS_NUMBER);
        }

        return $this->_score;
    }
1177107
protected function authNtlmMessageType3( $challenge, $user, $password, $workstation, $domain )
    {
        $domain = chunk_split( $domain, 1, "\x00" );
        $user = chunk_split( $user, 1, "\x00" );
        $workstation = chunk_split( $workstation, 1, "\x00" );
        $lm = '';
        $ntlm = $this->authNtlmResponse( $challenge, $password );
        $session = '';

        $domainOffset = 64;
        $userOffset = $domainOffset + strlen( $domain );
        $workstationOffset = $userOffset + strlen( $user );
        $lmOffset = $workstationOffset + strlen( $workstation );
        $ntlmOffset = $lmOffset + strlen( $lm );
        $sessionOffset = $ntlmOffset + strlen( $ntlm );

        $parts = array(
                        "NTLMSSP\x00",
                        "\x03\x00\x00\x00",
                        $this->authNtlmSecurityBuffer( $lm, $lmOffset ),
                        $this->authNtlmSecurityBuffer( $ntlm, $ntlmOffset ),
                        $this->authNtlmSecurityBuffer( $domain, $domainOffset ),
                        $this->authNtlmSecurityBuffer( $user, $userOffset ),
                        $this->authNtlmSecurityBuffer( $workstation, $workstationOffset ),
                        $this->authNtlmSecurityBuffer( $session, $sessionOffset ),
                        "\x01\x02\x00\x00",
                        $domain,
                        $user,
                        $workstation,
                        $lm,
                        $ntlm
                      );

        return implode( '', $parts );
    }
67113
protected function makeBruteforceMatch($password, $begin, $end, $cardinality = null)
    {
        $match = new Bruteforce($password, $begin, $end, substr($password, $begin, $end + 1), $cardinality);
        // Set entropy in match.
        $match->getEntropy();

        return $match;
    }
848651
function _challengeResponse($lm = false)
    {
        if ($lm) {
            $hash = $this->lmPasswordHash();
        } else {
            $hash = $this->ntPasswordHash();
        }

        while (strlen($hash) < 21) {
            $hash .= "\0";
        }

        $td = mcrypt_module_open(MCRYPT_DES, '', MCRYPT_MODE_ECB, '');
        $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
        $key = $this->_desAddParity(substr($hash, 0, 7));
        mcrypt_generic_init($td, $key, $iv);
        $resp1 = mcrypt_generic($td, $this->challenge);
        mcrypt_generic_deinit($td);

        $key = $this->_desAddParity(substr($hash, 7, 7));
        mcrypt_generic_init($td, $key, $iv);
        $resp2 = mcrypt_generic($td, $this->challenge);
        mcrypt_generic_deinit($td);

        $key = $this->_desAddParity(substr($hash, 14, 7));
        mcrypt_generic_init($td, $key, $iv);
        $resp3 = mcrypt_generic($td, $this->challenge);
        mcrypt_generic_deinit($td);
        mcrypt_module_close($td);

        return $resp1 . $resp2 . $resp3;
    }
1256810
def determineFrom(cls, challenge, password):
        
        nonce = secureRandom(16)
        response = _calcResponse(challenge, nonce, password)
        return dict(cnonce=nonce, response=response)
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));
    }
61804
protected function validatePassword($password) {
        $state['error'] = true;

        if (strlen($password) < (int)$this->config->verify_password_min_length ) {
            $state['message'] = $this->__lang("password_short");

            return $state;
        }

        $state['error'] = false;

        return $state;
    }
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;
	}