Dialup.Auth.SessionToken (Dialup v0.2.0)

Copy Markdown View Source

Opaque session token generation and hashing.

Raw tokens are sent to clients (cookie). Only SHA-256 hashes are stored in the database, following the phx_gen_auth model.

Summary

Functions

Generates a URL-safe opaque session token.

Hashes a raw token for database storage.

Returns the TTL in seconds for a token context.

Constant-time comparison of a raw token against a stored hash.

Functions

generate()

@spec generate() :: binary()

Generates a URL-safe opaque session token.

hash(token)

@spec hash(binary()) :: binary()

Hashes a raw token for database storage.

ttl(context)

@spec ttl(atom()) :: non_neg_integer()

Returns the TTL in seconds for a token context.

valid?(token, stored_hash)

@spec valid?(binary(), binary()) :: boolean()

Constant-time comparison of a raw token against a stored hash.