# PasswordVerifier

> Verifies credentials for an existing application's directory identity without creating a Yii session.

[API reference](/docs/api/index.md) › [LDAP](/docs/extensions/ldap/reference/index.md) › PasswordVerifier

| class | `yii2\extensions\ldap\PasswordVerifier` |
| --- | --- |
| Extends | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Source | [`src/PasswordVerifier.php`](https://github.com/yii2-extensions/ldap/blob/main/src/PasswordVerifier.php#L28) |

Verifies credentials for an existing application's directory identity without creating a Yii session.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-host"></span>`$host` | `string` | Directory hostname matching the server certificate, without a scheme or port. Default: `''`. | `PasswordVerifier` |
| <span id="property-port"></span>`$port` | `int` | LDAP port accepting StartTLS, not an implicit TLS port. Default: `389`. | `PasswordVerifier` |
| <span id="property-timeout"></span>`$timeout` | `int` | Seconds allowed for the network connection and for each directory reply. Default: `5`. | `PasswordVerifier` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/baseobject/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/baseobject/index.md#method-__get) | Returns the value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/baseobject/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/baseobject/index.md#method-__set) | Sets value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/baseobject/index.md#method-__unset) | Sets an object property to null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/baseobject/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/baseobject/index.md#method-hasProperty) | Returns a value indicating whether a property is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`init()`](#method-init) | Validates the endpoint and timeout without opening a connection. | `PasswordVerifier` |
| [`verify()`](#method-verify) | Checks the password against a principal obtained from the application's trusted identity mapping. | `PasswordVerifier` |
| [`newConnection()`](#method-newConnection) protected | Creates an unconnected transport for one verification attempt. | `PasswordVerifier` |

## Method details

### init() <span id="method-init"></span>

```php
public function init(): void
```

Validates the endpoint and timeout without opening a connection.

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): when the endpoint or timeout is invalid.

### verify() <span id="method-verify"></span>

```php
public function verify(string $principal, string $password): bool
```

Checks the password against a principal obtained from the application's trusted identity mapping.

Returns `false` for missing credentials, NUL bytes, or a rejected password. Each attempt owns its connection,
even in a persistent worker. No directory error or submitted credential is included in exception messages.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$principal` | `string` | Bind name resolved from the application's trusted identity mapping. |
| `$password` | `string` | Password submitted by the user. |

**Returns**

`bool`: Whether the directory accepted the credentials.

**Throws**

- [`DirectoryUnavailableException`](/docs/extensions/ldap/reference/directoryunavailableexception/index.md): when the connection cannot be secured or the directory fails.

### newConnection() <span id="method-newConnection"></span>

```php
protected function newConnection(): yii2\extensions\ldap\DirectoryConnection
```

Creates an unconnected transport for one verification attempt.

**Returns**

[`DirectoryConnection`](/docs/extensions/ldap/reference/directoryconnection/index.md): Transport with no open LDAP handle.