Download the PHP package asernum/sdk-client-asafe without Composer
On this page you can find all versions of the php package asernum/sdk-client-asafe. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download asernum/sdk-client-asafe
More information about asernum/sdk-client-asafe
Files in asernum/sdk-client-asafe
Package sdk-client-asafe
Short Description TOTP (RFC 6238) / Asafe compatible 2FA helper.
License MIT
Informations about the package sdk-client-asafe
asernum/sdk-client-asafe (PHP)
TOTP (RFC 6238) library for generating and verifying one-time codes, compatible with Asafe and other TOTP-compatible authenticator apps.
Installation
Usage
Basic example
Understanding the window parameter
The window parameter in verifyKey() allows for a small time drift. TOTP codes change every 30 seconds (by default); a clock difference between the server and the user's device can cause verification to fail.
Behavior:
window = 0: accepts only the code for the current periodwindow = 1(default): accepts codes for the current, previous, and next period (±30 seconds)window = 2: accepts codes over ±2 periods (±60 seconds)
Example:
When to use which value:
window = 0: maximum security (but may fail if clocks are out of sync)window = 1: general use (good balance of security and usability)window = 2or more: when clocks may be poorly synchronized
API
generateSecret(length?: int): string
Generates a random secret key encoded in base32.
length: optional. Number of characters (default: 32, ~160 bits)
getOtpAuthUrl(account: string, issuer: string, secret: string): string
Creates an otpauth:// URL compatible with Asafe and other TOTP apps.
account: user identifier (e.g. email address)issuer: service name (e.g. "MyCompany")secret: secret key fromgenerateSecret()
getCurrentOtp(secret: string, options?: array): string
Generates the current TOTP code for the given secret.
secret: the secret keyoptions: optional TOTP configuration (period,digits,algorithm)
verifyKey(secret: string, token: string, window?: int, options?: array): bool
Verifies whether a TOTP token is valid.
secret: the secret keytoken: the OTP code to verify (user input)window: optional. Time tolerance in periods (default: 1). See Understanding thewindowparameter aboveoptions: optional TOTP configuration- Returns:
trueif the token is valid,falseotherwise
License
MIT
All versions of sdk-client-asafe with dependencies
ext-hash Version *