Skip to content

MakeTOTP()

ts
function MakeTOTP(validForSeconds: number): string;

Generates a TOTP (time-based one-time password) code using the server's configured TOTP secret. The code is valid for the number of seconds specified by validForSeconds. Returns the 6-digit code as a string, or an empty string if generation fails.

The algorithm used is SHA-512 with 6 digits, consistent with ValidateTOTP().

NOTE

MakeTOTP and ValidateTOTP use Syncplify Server!'s own global TOTP secret (configured by the administrator). They are not tied to any individual user's 2FA enrollment. Typical use cases include generating a machine-to-machine auth token that a remote consumer can verify, or generating a time-limited code to embed in a notification.

ParameterTypeRequirementExplanation
validForSecondsnumberrequiredHow many seconds the generated code should remain valid
Return valueExplanation
string6-digit TOTP code, or "" on failure

Example

ts
// Generate a code valid for 60 seconds and include it in an email
var code = MakeTOTP(60);
if (code !== '') {
  SendMail(
    'server@example.com',
    'partner@example.com',
    'Your one-time access code',
    'Your code is: ' + code + '. It expires in 60 seconds.'
  );
}