Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Deprecated   Guides   Examples   Videos
New in version: 11.3   11.4   11.5   12.0   12.1   12.2   12.3   12.4   12.5   13.0    Statistic    FMM    Blog  

TOTP.Calculate

Calculates a Time-based one-time password.

Component Version macOS Windows Linux Server iOS SDK
TOTP 12.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "TOTP.Calculate"; Key; TimeNow; TimeStart; TimeStep; DigitCount { ; Algorithm; DecodeBase32 } )   More

Parameters

Parameter Description Example Flags
Key The secret to use. "12345678"
TimeNow The current time.
In seconds.
MBS("TOTP.CurrentTime")
TimeStart The start time.
In seconds.
0
TimeStep The step value defining the duration the code is valid.
In Seconds.
30
DigitCount The number of digits to generate.
Ranges usually from 4 to 9.
6
Algorithm Available in MBS FileMaker Plugin 12.5 or newer.
The algorithm to use.
Can be empty, SHA1, SHA256 or SHA512.
Default is SHA1 if nothing is passed.
"SHA1" Optional
DecodeBase32 Available in MBS FileMaker Plugin 12.5 or newer.
Whether the password is base32 encoded and should be decoded.
1 Optional

Result

Returns value or error.

Description

Calculates a Time-based one-time password.
Uses SHA-1 as hash algorithm.

The result is returned as number and may miss leading zeros, if you just convert it to text.

Examples

Calculate a code:

Set Variable [$code; Value: MBS( "TOTP.Calculate"; "12345678"; MBS("TOTP.CurrentTime"); 0; 30; 6 ) ]

Test the function with SHA-1:

Let([
key = "12345678901234567890";
TimeNow = 59;
TimeStep = 30;
TimeStart = 0;
Digits = 8;
r = MBS( "TOTP.Calculate"; Key; TimeNow; TimeStart; TimeStep; Digits )
]; r)

Example result: 94287082

Test the function with SHA-256:

Let([
key = "12345678901234567890123456789012";
TimeNow = 59;
TimeStep = 30;
TimeStart = 0;
Digits = 8;
r = MBS( "TOTP.Calculate"; Key; TimeNow; TimeStart; TimeStep; Digits; "sha256" )
]; r)

Example result: 46119246

Test the function with SHA-512:

Let([
key = "1234567890123456789012345678901234567890123456789012345678901234";
TimeNow = 59;
TimeStep = 30;
TimeStart = 0;
Digits = 8;
r = MBS( "TOTP.Calculate"; Key; TimeNow; TimeStart; TimeStep; Digits; "sha512" )
]; r)

Example result: 90693936

Test with base32 decoding:

MBS("TOTP.Calculate"; "JBSWY3DPEHPK3PXP"; MBS("TOTP.CurrentTime"); 0; 30; 6; "SHA1")

See also

Release notes

Example Databases

Blog Entries

Videos

Created 24th May 2022, last changed 14th October 2022


TAPI.Unpark - TOTP.CurrentTime

Feedback: Report problem or ask question.


Start Chat