BoxLang 🚀 A New JVM Dynamic Language Learn More...

totp

v1.0.11 Modules

totp

Available on ForgeBox Tested With TestBox

Compatible with ColdFusion 2016 Compatible with ColdFusion 2018 Compatible with Lucee 5

A CFML Implementation of Time-based One-time Passwords

Inspiration

Installation

Install via CommandBox and ForgeBox: box install totp

If you install manually, you need to download the CFzxing library to /modules/CFzxing.

Usage

Obtain a new instance of TOTP using WireBox or simplying by creating a new instance (new TOTP()).

WireBox/ColdBox is NOT required to use this module.

You can view an example of using this library by viewing the index.cfm file in the root of this module.

generate

Generates a secret, authenticator url, and a QR code for a given email and issuer. The secret should be stored securely and associated to the user who created it. It is also recommended that you have the user verify a code using the secret before saving the secret.

NameTypeRequiredDefaultDescription
emailstringtrue The email address of the user associated with this secret.
issuerstringtrue The name of the issuer of this secret.
lengthnumericfalse32The length of the secret key.
widthnumericfalse128The width of the QR code.
heightnumericfalse128The height of the QR code.

generateSecret

Generates a Base32 string to use as a secret key when generating and verifying TOTPs. This key should be stored securely and associated to the user who created it. It is also recommended that you have the user verify a code using the secret before saving the secret.

NameTypeRequiredDefaultDescription
lengthnumericfalse32The length of the secret key.

generateUrl

Generates a URL to use with authenticator apps containing the email, issuer, and generated secret key.

NameTypeRequiredDefaultDescription
emailstringtrue The email address of the user associated with this secret.
issuerstringtrue The name of the issuer of this secret.
lengthnumericfalse32The length of the secret key.

generateQRCode

Generates a QR Code to use with authenticator apps containing the authenticator url.

NameTypeRequiredDefaultDescription
authenticatorUrlstringtrue The authenticator url to encode in a QR code, usually from calling generateUrl.
widthnumericfalse128The width of the QR code.
heightnumericfalse128The height of the QR code.

generateRecoveryCodes

Generates an array of recovery codes.

Each code composed of numbers and lower case characters from latin alphabet (36 possible characters). The code is split in groups separated with dash for better readability. For example: 4ckn-xspn-et8t-xgr0

NameTypeRequiredDefaultDescription
amountnumerictrue The amount of codes to generate.

generateCode

Generates a Time-based One-time Password (TOTP) for a given secret.

NameTypeRequiredDefaultDescription
secretstringtrue The Base32 string to use when generating the code.
digitsnumericfalse6The number of digits of the code to return.
algorithmstringfalse"SHA1"The algorithm to use when generating the code. Valid algorithms are: MD5, SHA1, SHA256, SHA384, SHA512.
timenumericfalsenowThe current time (expressed as seconds since January 1, 1970).
timePeriodnumericfalse30The time period the code is valid, in seconds.

verifyCode

Verifies a given TOTP for a given secret.

NameTypeRequiredDefaultDescription
secretstringtrue The Base32 string to use when verifying the code. (This needs to be the same secret used to generate the code.)
codestringtrue The code to verify.
algorithmstringfalse"SHA1"The algorithm to use when verifying the code. (This needs to be the same algorithm used to generate the code.) Valid algorithms are: MD5, SHA1, SHA256, SHA384, SHA512.
timenumericfalsenowThe current time (expressed as seconds since January 1, 1970).
timePeriodnumericfalse30The time period the code is valid, in seconds.
allowedTimePeriodDiscrepancynumericfalse1The number of periods, before and after, a code is considered valid. By default, a code is valid for 30 seconds before to 30 seconds after its valid period for a total of 90 seconds.

v1.0.11

03 Sep 2024 — 15:51: 46 UTC

other

$ box install totp

No collaborators yet.
     
  • {{ getFullDate("2022-01-25T23:41:11Z") }}
  • {{ getFullDate("2024-09-03T15:51:51Z") }}
  • 4,166
  • 837