PasswordlessAuth v0.3.0 PasswordlessAuth View Source

PasswordlessAuth provides functionality for generating numeric codes that can be used for verifying a user's ownership of a phone number, email address or any other identifying address.

It is designed to be used in a verification system, such as a passwordless authentication flow or as part of multi-factor authentication (MFA).

Link to this section Summary

Functions

Generates a verification code for the given recipient. The code is a string of numbers that is code_length characters long (defaults to 6).

Removes a code from state based on the given recipient

Verifies that a the given recipient has the given attempt_code stored in state and that the code hasn't expired.

Link to this section Types

Link to this type

verification_failed_reason()

View Source

Specs

verification_failed_reason() ::
  :attempt_blocked | :code_expired | :does_not_exist | :incorrect_code

Link to this section Functions

Link to this function

generate_code(recipient, code_length \\ 6)

View Source

Specs

generate_code(String.t(), integer()) :: String.t()

Generates a verification code for the given recipient. The code is a string of numbers that is code_length characters long (defaults to 6).

The verification code is valid for the number of seconds given to the verification_code_ttl config option (defaults to 300)

Arguments:

  • recipient: A reference to the recipient of the code. This is used for verifying the code with verify_code/2
  • code_length: The length of the code. Defaults to 6.

Returns the code.

Specs

remove_code(String.t()) ::
  {:ok, PasswordlessAuth.VerificationCode.t()} | {:error, :does_not_exist}

Removes a code from state based on the given recipient

Returns {:ok, %VerificationCode{...}} or {:error, :reason}.

Link to this function

verify_code(recipient, attempt_code)

View Source

Specs

verify_code(String.t(), String.t()) ::
  :ok | {:error, verification_failed_reason()}

Verifies that a the given recipient has the given attempt_code stored in state and that the code hasn't expired.

Returns :ok or {:error, :reason}.

Examples

iex> PasswordlessAuth.verify_code("+447123456789", "123456")
{:error, :does_not_exist}