PHPackages                             robinpowered/php-ntlm - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. robinpowered/php-ntlm

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

robinpowered/php-ntlm
=====================

Message encoder/decoder and password hasher for the NTLM authentication protocol

v0.5.0(7y ago)17117.6k↓36.8%7[2 issues](https://github.com/robinpowered/php-ntlm/issues)[1 PRs](https://github.com/robinpowered/php-ntlm/pulls)1Apache-2.0PHP

Since Aug 27Pushed 1y ago11 watchersCompare

[ Source](https://github.com/robinpowered/php-ntlm)[ Packagist](https://packagist.org/packages/robinpowered/php-ntlm)[ RSS](/packages/robinpowered-php-ntlm/feed)WikiDiscussions master Synced yesterday

READMEChangelog (9)Dependencies (5)Versions (12)Used By (1)

PHP NTLM
========

[](#php-ntlm)

[![Build Status](https://camo.githubusercontent.com/12db6724d8fd4c43ae83f1318bf5c6c181e0b3f107a5077211fb81fbe59f0281/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f726f62696e706f77657265642f7068702d6e746c6d2e7376673f7374796c653d666c6174)](https://travis-ci.org/robinpowered/php-ntlm)[![Quality Score](https://camo.githubusercontent.com/83683942e4c9795eba37aca029a1fd65cf2f669ad5e5ad7878672d23a168f09f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f726f62696e706f77657265642f7068702d6e746c6d2e7376673f7374796c653d666c6174)](https://scrutinizer-ci.com/g/robinpowered/php-ntlm/)[![Latest Stable Version](https://camo.githubusercontent.com/691453545705cdce9b8f50c9e3d3d0793c769610a7a294d311f25536fc461df9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f726f62696e706f77657265642f7068702d6e746c6d2e7376673f7374796c653d666c6174)](https://github.com/robinpowered/php-ntlm/releases)

PHP-NTLM is a library that handles the encoding and decoding of messages used in the challenge-and-response flow of the NTLM authentication protocol, while also providing separate injectable credential hashing mechanisms to allow for a more secure version of a credential for storage (rather than storing passwords in "plain-text").

Features
--------

[](#features)

- NTLM client message encoding and decoding
- Multiple text-encoding native-extensions supported
- LM, NTv1, and NTv2 hashing algorithms supported

Requirements
------------

[](#requirements)

- 64-bit PHP runtime (NTLM negotiation bit flags extend beyond the 32-bit integer size)
- PHP `>=7.1.0`

Installation
------------

[](#installation)

1. [Get Composer](https://getcomposer.org/)
2. Add `robinpowered/php-ntlm` to your Composer required dependencies: `composer require robinpowered/php-ntlm`
3. Include the [Composer autoloader](https://getcomposer.org/doc/01-basic-usage.md#autoloading)

Example Usage
-------------

[](#example-usage)

```
// Using Guzzle
$client = new Client();
$request = new Request('get', 'https://my-exchange-url.com');
$user_name = 'user_name';
$password = 'password';
$target_name = 'target_name';
$host_name = 'host_name';

$encoding_converter = new MbstringEncodingConverter();
$random_byte_generator = new NativeRandomByteGenerator();
$hasher_factory = HasherFactory::createWithDetectedSupportedAlgorithms();

$negotiate_message_encoder = new NegotiateMessageEncoder($encoding_converter);
$challenge_message_decoder = new ChallengeMessageDecoder();

$keyed_hasher_factory = KeyedHasherFactory::createWithDetectedSupportedAlgorithms();

$nt1_hasher = new NtV1Hasher($hasher_factory, $encoding_converter);
$nt2_hasher = new NtV2Hasher($nt1_hasher, $keyed_hasher_factory, $encoding_converter);

$authenticate_message_encoder = new NtlmV2AuthenticateMessageEncoder(
    $encoding_converter,
    $nt2_hasher,
    $random_byte_generator,
    $keyed_hasher_factory
);

$negotiate_message = $negotiate_message_encoder->encode(
    $target_name,
    $host_name
);

// Send negotiate message
$request->setHeader('Authorization', sprintf('NTLM %s', base64_encode($negotiate_message)));
$response = $client->send($request);

// Decode returned challenge message
$authenticate_headers = $response->getHeaderAsArray('WWW-Authenticate');
foreach ($authenticate_headers as $header_string) {
    $ntlm_matches = preg_match('/NTLM( (.*))?/', $header_string, $ntlm_header);

    if (0 < $ntlm_matches && isset($ntlm_header[2])) {
        $raw_server_challenge = base64_decode($ntlm_header[2]);
        break;
    }
}
$server_challenge = $challenge_message_decoder->decode($raw_server_challenge);

$authenticate_message = $authenticate_message_encoder->encode(
    $user_name,
    $target_name,
    $host_name,
    new Password($password),
    $server_challenge
);

// Send authenticate message
$request->setHeader('Authorization', sprintf('NTLM %s', base64_encode($authenticate_message)));
$client->send($request);
```

TODO
----

[](#todo)

- LM hashing
- NTv1 hashing
- NTv2 hashing
- NTLM negotiate message encoding
- NTLM challenge message decoding
    - Message structure and data validation
    - Negotiate flag decoding
    - Server challenge "nonce" handling
    - TargetName parsing/handling
    - (Optional) TargetInfo parsing/handling
        - (Optional) AV\_PAIR decoding
    - (Optional) Version parsing/handling (for debugging purposes only)
- NTLM authenticate message encoding
    - NTLM v1 response support
    - NTLM v2 response support
    - Extended session security (NTLM2 session key) support
    - (Add-on) Encrypted session key exchange support
- Datagram ("connectionless") support
- Tests

License
-------

[](#license)

**PHP-NTLM** is licensed under the [Apache License, Version 2.0](LICENSE).

---

Copyright 2019 Robin Powered, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

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.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 96.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~167 days

Recently: every ~313 days

Total

9

Last Release

2627d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ae34d0c08d757bdf3a2fe43824bfbb6d6fe570fcb2cfb2bb01af52e1384dc13f?d=identicon)[Rican7](/maintainers/Rican7)

![](https://www.gravatar.com/avatar/7a49063462d21063921fb4d5ffa06485e6e306e218a8392833b545467d092ec9?d=identicon)[brianmuse](/maintainers/brianmuse)

---

Top Contributors

[![Rican7](https://avatars.githubusercontent.com/u/742384?v=4)](https://github.com/Rican7 "Rican7 (155 commits)")[![brianmuse](https://avatars.githubusercontent.com/u/548885?v=4)](https://github.com/brianmuse "brianmuse (4 commits)")[![mcos](https://avatars.githubusercontent.com/u/330871?v=4)](https://github.com/mcos "mcos (2 commits)")

---

Tags

authenticationchallengehashlmnegotiatentlmntlm-authentication-protocolntv1ntv1-hashingntv2ntv2-hashingphpAuthenticationhashNTLMntlm

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/robinpowered-php-ntlm/health.svg)

```
[![Health](https://phpackages.com/badges/robinpowered-php-ntlm/health.svg)](https://phpackages.com/packages/robinpowered-php-ntlm)
```

###  Alternatives

[tymon/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

11.7k51.8M371](/packages/tymon-jwt-auth)[league/oauth2-server

A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.

6.7k147.0M290](/packages/league-oauth2-server)[league/oauth2-client

OAuth 2.0 Client Library

3.8k128.7M1.3k](/packages/league-oauth2-client)[paragonie/sodium_compat

Pure PHP implementation of libsodium; uses the PHP extension if it exists

931145.2M177](/packages/paragonie-sodium-compat)[google/auth

Google Auth Library for PHP

1.4k294.2M218](/packages/google-auth)[pragmarx/google2fa

A One Time Password Authentication package, compatible with Google Authenticator.

2.0k97.9M239](/packages/pragmarx-google2fa)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
