TwoFactorInACan v0.1.0 TwoFactorInACan.Hotp View Source
Functions for working with the HMAC-based One Time Password algorithm as defined in RFC 4226.
For details on RFC 4226, see https://tools.ietf.org/rfc/rfc4226.txt.
Link to this section Summary
Functions
Generates a token from a shared secret and a counter which can be synchronized.
Link to this section Functions
Link to this function
generate_token(secret, count, opts \\ []) View Source
Generates a token from a shared secret and a counter which can be synchronized.
This token can be used by one party to verify whether another party has the same secret.
Options:
:secret_format
- the format that the secret is passed in as. Options include::binary
(default):base32
:base64
:token_length
(Default: 6) - the length of the generated token. A longer token is harder to guess and thus more secure. A longer token can also be more difficult for users to accurately transmit. Although everything inTwoFactorInACan
supports variable token length, you should be sure that other apps and programs used support the token length set here.
Examples
iex> secret = TwoFactorInACan.Secrets.generate_totp_secret()
iex> TwoFactorInACan.Hotp.generate_token(secret, 0)
"866564"
iex> TwoFactorInACan.Hotp.generate_token(secret, 1)
"532769"
iex> TwoFactorInACan.Hotp.generate_token(secret, 0, token_length: 10)
"1807866564"