Documentation

RecoveryCodeService

Generates and verifies one-time recovery codes.

Tags
since
3.1.2

Table of Contents

Constants

ENTROPY_BYTES  = 10
Random bytes of entropy per code (10 bytes = 20 hex chars = 80 bits).
GROUP_SIZE  = 5
Characters per dash-separated group in the displayed code.

Properties

$tokenHasher  : TokenHasher

Methods

__construct()  : mixed
generate()  : array{code: string, hash: string}
Generate a new recovery code.
verify()  : bool
Verify a user-entered code against a stored hash.
canonicalize()  : string
Reduce user input to the canonical form the hash is computed over.
format()  : string
Group a raw code into dash-separated chunks for display.

Constants

ENTROPY_BYTES

Random bytes of entropy per code (10 bytes = 20 hex chars = 80 bits).

private mixed ENTROPY_BYTES = 10

GROUP_SIZE

Characters per dash-separated group in the displayed code.

private mixed GROUP_SIZE = 5

Properties

Methods

generate()

Generate a new recovery code.

public generate() : array{code: string, hash: string}
Return values
array{code: string, hash: string}

The human-readable code to show the user once, and the hash to store.

verify()

Verify a user-entered code against a stored hash.

public verify(string $input, string $hash) : bool
Parameters
$input : string

The code as typed by the user (any case/spacing).

$hash : string

The stored hash to check against.

Return values
bool

canonicalize()

Reduce user input to the canonical form the hash is computed over.

private canonicalize(string $input) : string
Parameters
$input : string
Return values
string

format()

Group a raw code into dash-separated chunks for display.

private format(string $raw) : string
Parameters
$raw : string
Return values
string

        
On this page

Search results