Install NimbleTOTP via mix
masterTo use nimble_totp in your Elixir project, add it to your deps list in your mix.exs file.
def deps do
[
{:nimble_totp, "~> 1.0"}
]
endrepository·master·Indexed 19 days ago
https://github.com/dashbitco/nimble_totpA lightweight Elixir library for implementing Time-based One-Time Passwords (TOTP) for two-factor authentication (2FA). It provides functionality to generate random secrets, create otpauth URIs for QR codes, generate verification codes, and validate user-provided codes.
To use nimble_totp in your Elixir project, add it to your deps list in your mix.exs file.
def deps do
[
{:nimble_totp, "~> 1.0"}
]
endNimbleTOTP provides functions to generate the current code and verify a user-provided code against a secret.
NimbleTOTP.verification_code(secret): Returns the current Time-Based One-Time Password as a string.NimbleTOTP.valid?(secret, code): Returns true if the provided code is valid for the given secret, otherwise false.# Generate the current code
NimbleTOTP.verification_code(secret)
#=> "569777"
# Validate a code
NimbleTOTP.valid?(secret, "569777")
#=> trueUse NimbleTOTP.otpauth_uri/3 to generate a URI that can be encoded into a QR code for users to scan with authenticator apps.
Arguments:
label: A string representing the user/account identifier (e.g., "Acme:alice").secret: The random byte secret generated via NimbleTOTP.secret/0.opts: A keyword list containing configuration, such as issuer: "Acme".NimbleTOTP.otpauth_uri("Acme:alice", secret, issuer: "Acme")
#=> "otpauth://totp/Acme:alice?secret=MFRGGZA&issuer=Acme"Use NimbleTOTP.secret/0 to generate a secret composed of random bytes. This secret is used for both generating URIs and validating subsequent OTP codes.
secret = NimbleTOTP.secret()
#=> <<63, 24, 42, 30, 95, 116, 80, 121, 106, 102>>