GoogleAuthenticator
in package
Table of Contents
Properties
- $PASS_CODE_LENGTH : mixed
- $SECRET_LENGTH : mixed
Methods
- checkCode() : bool
- Check a given code against a given secret
- generateSecret() : string
- Generate a secret key and encode as base32
- getQRData() : string
- For a given set of details, return the otpauth:// url for use in a QR code
- getQRImageUrl() : string
- Return a Google Charts url which generates a QR code image from some QR code data
- getCode() : string
- Calculate what the code for a given secret/time should be
Properties
$PASS_CODE_LENGTH
private
static mixed
$PASS_CODE_LENGTH
= 6
$SECRET_LENGTH
private
static mixed
$SECRET_LENGTH
= 20
Methods
checkCode()
Check a given code against a given secret
public
checkCode(string $secret, string $code) : bool
Does the check three times, for current time, one period before, and one period after This is to allow for clock drift
Parameters
- $secret : string
-
The secret key, as a base32 string
- $code : string
-
Numeric code entered by the user to be checked
Return values
bool —True if code matches, false if it does not
generateSecret()
Generate a secret key and encode as base32
public
generateSecret() : string
NOTE: Only cryptographically secure in PHP 7.0 onwards (uses "random_bytes" method) On earlier versions of PHP this method isn't available so rand() is used instead
Return values
string —Randomly generated secret key
getQRData()
For a given set of details, return the otpauth:// url for use in a QR code
public
getQRData(string $issuer, string $user, string $host, string $secret) : string
Parameters
- $issuer : string
-
The name of the entity issuing the token (e.g. the website, company, etc)
- $user : string
-
Username who is receiving the token
- $host : string
-
Hostname where the token is issued
- $secret : string
-
Randomly-generated secret key, as a base32 string
Return values
string —URL with the otpauth:// scheme
getQRImageUrl()
Return a Google Charts url which generates a QR code image from some QR code data
public
getQRImageUrl(string $qr_data) : string
Parameters
- $qr_data : string
-
Data for the QR code
Return values
string —Image URL
getCode()
Calculate what the code for a given secret/time should be
protected
getCode(string $secret, int $time) : string
Parameters
- $secret : string
-
The secret key, as a base32 string
- $time : int
-
Unix timestamp, floored to a 30-sec increment
Return values
string —The calculated code, numeric