Countersign.Code (Countersign v0.1.0)

Copy Markdown View Source

A signing code (signing_codes): a six-digit one-time code sent to the address the link went to.

The code is stored as a Bcrypt hash (code_hash) and, encrypted, as code_ciphertext, so it never travels in clear through job arguments. It expires 10 minutes after it is issued and allows max_attempts/0 guesses, each spent by a conditional UPDATE before Bcrypt runs.

Summary

Functions

A uniformly random six-digit code, "000000" to "999999".

Guesses allowed per code.

Seconds a code stays valid after it is issued.

Types

t()

@type t() :: %Countersign.Code{
  __meta__: term(),
  attempts: non_neg_integer() | nil,
  channel: :email | :sms | nil,
  code_ciphertext: binary() | nil,
  code_hash: String.t() | nil,
  consumed_at: DateTime.t() | nil,
  expires_at: DateTime.t() | nil,
  id: Ecto.UUID.t() | nil,
  inserted_at: DateTime.t() | nil,
  signing_request: term(),
  signing_request_id: Ecto.UUID.t() | nil,
  updated_at: DateTime.t() | nil
}

Functions

generate()

@spec generate() :: String.t()

A uniformly random six-digit code, "000000" to "999999".

Drawn by rejection sampling from 24 random bits, so no value is more likely than another (a plain rem over 2^24 would favour the low values).

max_attempts()

@spec max_attempts() :: pos_integer()

Guesses allowed per code.

ttl_seconds()

@spec ttl_seconds() :: pos_integer()

Seconds a code stays valid after it is issued.