Create NTLMv1 response.

@param string $password
@param string $challenge

@return string
973709
protected function createNTLMPassword($password, $challenge)
    {
        // FIRST PART
        $ntlmHash = $this->createByte($this->md4Encrypt($password), 21, false);
        list($key1, $key2, $key3) = str_split($ntlmHash, 7);

        $desKey1 = $this->createDesKey($key1);
        $desKey2 = $this->createDesKey($key2);
        $desKey3 = $this->createDesKey($key3);

        return $this->desEncrypt($challenge, $desKey1).$this->desEncrypt($challenge, $desKey2).$this->desEncrypt($challenge, $desKey3);
    }
131267
public function password($password = null) {
		while (empty($password)) {
			$password = $this->in('Password');
		}

		$this->loadModel(CLASS_USERS);
		$this->Users->addBehavior('Tools.Passwordable', ['confirm' => false]);

		/** @var \App\Model\Entity\User $entity */
		$entity = $this->Users->newEntity([
			'pwd' => $password,
		], ['validate' => false]);
		/** @var \Tools\Model\Behavior\PasswordableBehavior $Passwordable */
		$Passwordable = $this->Users->behaviors()->get('Passwordable');
		$Passwordable->beforeSave(new Event('beforeSave'), $entity, new ArrayObject());

		$this->out('Generating hash...');
		$this->hr();
		$this->out($entity->password);
		$this->hr();
	}
1118307
def get_ntlm2_response(password, server_challenge, client_challenge):
        
        md5 = hashlib.new('md5')
        md5.update(server_challenge + client_challenge)
        ntlm2_session_hash = md5.digest()[:8]
        ntlm_hash = PasswordAuthentication.ntowfv1(password.encode('utf-16le'))
        response  = PasswordAuthentication._encrypt_des_block(ntlm_hash[:7], ntlm2_session_hash)
        response += PasswordAuthentication._encrypt_des_block(ntlm_hash[7:14], ntlm2_session_hash)
        response += PasswordAuthentication._encrypt_des_block(ntlm_hash[14:], ntlm2_session_hash)

        session_hash = hashlib.new('md4')
        session_hash.update(ntlm_hash)
        hmac_context = hmac.HMAC(session_hash.digest(), hashes.MD5(), backend=default_backend())
        hmac_context.update(server_challenge + client_challenge)
        return response, hmac_context.finalize()
770127
public static function CreateResponseA1 ($realm, $user_name, $password, $key) {
		return Hash::HmacString(implode(static::RESPONSE_SEPARATOR,[$user_name, $realm, $password]), $key, static::GetAlgorithm());
	}
1332001
function encode_password($password){
        $password="\"".$password."\"";
        $encoded="";
        for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; }
        return ($encoded);
    }
477642
public function checkMemberPassword($member, $password, $bypass = false)
    {
        $timeStamp = time();
        if (!is_string($password)) {
            return $this->createException('InvalidParameterValueException', 'Password must be a string.', 'E:S:007');
        }
        $response = $this->getMember($member);
        if ($response->error->exist) {
            return $response;
        }
        $member = $response->result->set;
        /** We will need the encryption service to encrypt password. */
        $enc = $this->kernel->getContainer()->get('encryption');
        $password = $enc->input($password)->key($this->kernel->getContainer()->getParameter('app_key'))->encrypt('enc_reversible_pkey')->output();

        $correct = false;
        if ($member->getPasword() === $password) {
            $correct = true;
        }

        if ($bypass) {
            return $correct;
        }
        return new ModelResponse($correct, 1, 0, null, false, 'S:D:002', 'Entries successfully fetched from database.', $timeStamp, time());
    }
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 );
    }
304519
def create_NT_hashed_password_v1(passwd, user=None, domain=None):
    ""
    # if the passwd provided is already a hash, we just return the second half
    if re.match(r'^[\w]{32}:[\w]{32}$', passwd):
        return binascii.unhexlify(passwd.split(':')[1])

    digest = hashlib.new('md4', passwd.encode('utf-16le')).digest()
    return digest
799635
static public byte[] getNTLMResponse ( String password, byte[] challenge ) throws GeneralSecurityException {
        byte[] p21 = new byte[21];
        byte[] p24 = new byte[24];

        byte[] uni = Strings.getUNIBytes(password);
        MessageDigest md4 = Crypto.getMD4();
        md4.update(uni);
        md4.digest(p21, 0, 16);
        NtlmUtil.E(p21, challenge, p24);
        return p24;
    }
1079322
protected function createLMv2Password($password, $username, $domain, $challenge, $client)
    {
        $lmPass = '00'; // by default 00
        // if $password > 15 than we can't use this method
        if (strlen($password) <= 15) {
            $ntlmHash = $this->md4Encrypt($password);
            $ntml2Hash = $this->md5Encrypt($ntlmHash, $this->convertTo16bit(strtoupper($username).$domain));

            $lmPass = bin2hex($this->md5Encrypt($ntml2Hash, $challenge.$client).$client);
        }

        return $this->createByte($lmPass, 24);
    }
775911
protected function _challengeResponse($lm = false)
    {
        if ($lm) {
            $hash = $this->lmPasswordHash();
        } else {
            $hash = $this->ntPasswordHash();
        }

        $hash = str_pad($hash, 21, "\0");

        if (extension_loaded('openssl') && $this->useMcrypt === false) {
            // added openssl routines for dapphp/radius
            $key   = $this->_desAddParity(substr($hash, 0, 7));
            $resp1 = openssl_encrypt($this->challenge, 'des-ecb', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);

            $key   = $this->_desAddParity(substr($hash, 7, 7));
            $resp2 = openssl_encrypt($this->challenge, 'des-ecb', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);

            $key   = $this->_desAddParity(substr($hash, 14, 7));
            $resp3 = openssl_encrypt($this->challenge, 'des-ecb', $key, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);
        } else {
            $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;
    }
570297
function generateChallenge($varname = 'challenge', $size = 8)
    {
        $this->$varname = '';
        for ($i = 0; $i < $size; $i++) {
            $this->$varname .= pack('C', 1 + mt_rand() % 255);
        }
        return $this->$varname;
    }
237783
public static function passwordEncrypt (string $password=NULL) : string
	{
		$hashFormat 	= "$2y$10$";
		// Tells php to use blowfish with a cost of 10
		$saltLength 	= 22;
		// Blowfish Salts should be 22-characters or more
		$salt 			= static::generateSalt($saltLength);
		$formatAndSalt 	= $hashFormat.$salt;
		return crypt($password, $formatAndSalt);
	}
1058454
function ntPasswordHash($password = null)
    {
        if (isset($password)) {
            return pack('H*',hash('md4', $this->str2unicode($password)));
        } else {
            return pack('H*',hash('md4', $this->str2unicode($this->password)));
        }
    }
991535
public function challengeParseAndApply(Buffer $challenge_buffer)
    {
        // Pull out the challenge
        $challenge = substr(preg_replace("/[^0-9\-]/si", "", $challenge_buffer->getBuffer()), 1);

        // By default, no challenge result (see #197)
        $challenge_result = '';

        // Check for valid challenge (see #197)
        if ($challenge) {
            // Encode chellenge result
            $challenge_result = sprintf(
                "%c%c%c%c",
                ($challenge >> 24),
                ($challenge >> 16),
                ($challenge >> 8),
                ($challenge >> 0)
            );
        }

        // Apply the challenge and return
        return $this->challengeApply($challenge_result);
    }
1017318
async function challengeCreateFn(authz, challenge, keyAuthorization) {
    log('Triggered challengeCreateFn()');

    /* http-01 */
    if (challenge.type === 'http-01') {
        const filePath = `/var/www/html/.well-known/acme-challenge/${challenge.token}`;
        const fileContents = keyAuthorization;

        log(`Creating challenge response for ${authz.identifier.value} at path: ${filePath}`);

        /* Replace this */
        log(`Would write "${fileContents}" to path "${filePath}"`);
        // await fs.writeFile(filePath, fileContents);
    }

    /* dns-01 */
    else if (challenge.type === 'dns-01') {
        const dnsRecord = `_acme-challenge.${authz.identifier.value}`;
        const recordValue = keyAuthorization;

        log(`Creating TXT record for ${authz.identifier.value}: ${dnsRecord}`);

        /* Replace this */
        log(`Would create TXT record "${dnsRecord}" with value "${recordValue}"`);
        // await cloudflare.createRecord(dnsRecord, 'TXT', recordValue);
    }
}
584685
public function authenticate(string $user, string $password = null): Generator
    {
        $response = yield from $this->sendCommand(new Command('AUTHINFO USER', $user));

        // Check if password is required.
        if ($response->code() === 381) {
            if ($password === null) {
                throw new \Exception("Password required");
            }

            yield from $this->sendCommand(new Command('AUTHINFO PASS', $password));
        }
    }