Attempt to return the expected OTP code at the given time.
Compare this value against the user input to verify if their OTP is correct.
Attempt to parse a String representation of Key
back into a Key value
Builds a Key value from the parameters
https://rootprojects.org/authenticator/
import Base32
import String.Extra
import TOTP.Algorithm
import TOTP
keyResult : Result String Key
keyResult =
init
{ issuer = "ACME Co"
, user = "[email protected]"
, rawSecret = "HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ"
|> Base32.decode
|> Result.map String.Extra.fromCodePoints
|> Result.withDefault "<fail>"
, outputLength = Just 6
, periodSeconds = Just 30
, algorithm = TOTP.Algorithm.SHA1
}
-- expected String output
Result.map toString keyResult
--> Ok "otpauth://totp/ACME%20Co:[email protected]?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME%20Co&algorithm=SHA1&digits=6&period=30"
-- toString and fromString are reversible
Result.map toString keyResult
|> Result.map fromString
--> Ok (Result.toMaybe keyResult)
An opaque type to hold the configuration value for a TOTP.
This is the value to store in your database, by calling
toStringhttps://github.com/google/google-authenticator/wiki/Key-Uri-Format#algorithm