AuthShield v0.0.1 AuthShield.Credentials.TOTP View Source

Time-based One-Time Password (TOTP) is an extension of the HMAC-based One-time Password algorithm (HOTP) generating a one-time password by instead taking uniqueness from the current time.

It is usually used with mobile applications that receives the secret key and generates the code to be used in authentications.

Thi module implements an interface to deal with database transactions as inserts, updates, deletes, etc.

Link to this section Summary

Types

Transactional responses of failed

Transactional responses of success

Link to this section Types

Link to this type

failed_response()

View Source
failed_response() :: {:error, Ecto.Changeset.t()}

Transactional responses of failed

Link to this type

success_response()

View Source
success_response() :: {:ok, AuthShield.Credentials.Schemas.TOTP.t()}

Transactional responses of success

Link to this section Functions

Link to this function

check_totp?(totp, code, datetime_now \\ Timex.now())

View Source
check_totp?(
  totp :: AuthShield.Credentials.Schemas.TOTP.t(),
  totp_code :: String.t(),
  now :: DateTime.t()
) :: boolean()

Checks if the given TOTP code matches the generated one.

Exemples:

  # Using default timestamp
  AuthShield.Credentials.TOTP.check_pin?(totp, "332456")

  # Defining timestamp
  AuthShield.Credentials.TOTP.check_pin?(totp, "332456", Timex.now("America/Chicago"))

Deletes a AuthShield.Credentials.Schemas.TOTP register.

Exemples:

  AuthShield.Credentials.TOTP.delete(totp)

Deletes a AuthShield.Credentials.Schemas.TOTP register.

Similar to delete/1 but returns the struct or raises if the changeset is invalid.

Gets a AuthShield.Credentials.Schemas.TOTP register by its filters.

Exemples:

  AuthShield.Credentials.TOTP.get_by(user_id: "ecb4c67d-6380-4984-ae04-1563e885d59e")

Gets a AuthShield.Credentials.Schemas.TOTP register by its filters.

Similar to get_by/1 but returns the struct or raises if the changeset is invalid.

Creates a new AuthShield.Credentials.Schemas.TOTP register.

Exemples:

  # Simple insert
  AuthShield.Credentials.TOTP.insert(%{
    user_id: ecb4c67d-6380-4984-ae04-1563e885d59e",
    email: "lucas@gmail.com"
  })

  # All parameters
  AuthShield.Credentials.TOTP.insert(%{
    user_id: ecb4c67d-6380-4984-ae04-1563e885d59e",
    email: "lucas@gmail.com",
    issuer: "MyWebpage",
    digits: 4,
    period: 60
  })

Creates a new AuthShield.Credentials.Schemas.TOTP register.

Similar to insert/1 but returns the struct or raises if the changeset is invalid.

Returns a list of AuthShield.Credentials.Schemas.TOTP by its filters

Exemples:

  # Getting the all list
  AuthShield.Credentials.TOTP.list()

  # Filtering the list by field
  AuthShield.Credentials.TOTP.list(user_id: "ecb4c67d-6380-4984-ae04-1563e885d59e")