Elm implementation of RFC6238.
You can use this library with pablohirafuji/elm-qrcode to generate a QR code for your user to setup their OTP authenticator devices.
You can also use this library in the backendn (for example choonkeat/elm-webapp) to verify if a user input matches their OTP.
Initialize a Key
keyResult : Result String TOTP.Key.Key
keyResult =
TOTP.Key.init
{ issuer = "ACME Co"
, user = "[email protected]"
, rawSecret = "topsecret"
, outputLength = Nothing
, periodSeconds = Nothing
, algorithm = TOTP.Algorithm.SHA1
}And generate a QR code using pablohirafuji/elm-qrcode
view : TOTP.Key.Key -> Html msg
view key =
QRCode.fromString (TOTP.Key.toString key)
|> Result.map (QRCode.toSvg [])
|> Result.withDefault (text "Error while encoding to QRCode.")Check if a user input String matches the OTP code
TOTP.Key.code now key == inputStringSave Key into your database by converting it into a String first
TOTP.Key.toString keyLoad Key from your database,
TOTP.Key.fromString keySee the code in example. The running example instance can be found at elm-totp.netlify.app