[**Documentation**](../../../README)

***

[Documentation](../../../README) / [@zerotal/auth](../README) / EmailOtpBroker

# Class: EmailOtpBroker

Defined in: [auth/src/EmailOtpBroker.ts:46](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/auth/src/EmailOtpBroker.ts#L46)

## Constructors

### Constructor

> **new EmailOtpBroker**(`_opts`): `EmailOtpBroker`

Defined in: [auth/src/EmailOtpBroker.ts:51](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/auth/src/EmailOtpBroker.ts#L51)

#### Parameters

##### \_opts

[`EmailOtpOptions`](../interfaces/EmailOtpOptions)

#### Returns

`EmailOtpBroker`

## Methods

### send()

> **send**(`email`): `Promise`\<`void`\>

Defined in: [auth/src/EmailOtpBroker.ts:61](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/auth/src/EmailOtpBroker.ts#L61)

Generate a code, store its hash (with a zeroed attempt counter), and email the plaintext.

#### Parameters

##### email

`string`

The recipient address; the code is stored keyed by this email.

#### Returns

`Promise`\<`void`\>

***

### attempt()

> **attempt**(`email`, `code`): `Promise`\<`boolean`\>

Defined in: [auth/src/EmailOtpBroker.ts:78](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/auth/src/EmailOtpBroker.ts#L78)

Verify a code for an email. Returns `true` and consumes the code on success;
`false` when missing, expired, or wrong. Each wrong guess increments the
stored attempt counter; after `maxAttempts` failures the code is deleted so
an honest user can retry a typo, but a brute-forcer cannot walk the keyspace.

#### Parameters

##### email

`string`

The address the code was issued for.

##### code

`string`

The code entered by the user.

#### Returns

`Promise`\<`boolean`\>

`true` when the code is correct and unexpired (and is then consumed).
