PHP Class PHPGangsta_GoogleAuthenticator

Author: Michael Kliewe
Datei anzeigen Open project: phpgangsta/googleauthenticator Class Usage Examples

Protected Properties

Property Type Description
$_codeLength

Public Methods

Method Description
createSecret ( integer $secretLength = 16 ) : string Create new secret.
getCode ( string $secret, integer | null $timeSlice = null ) : string Calculate the code, with given secret and point in time.
getQRCodeGoogleUrl ( string $name, string $secret, string $title = null, array $params = [] ) : string Get QR-Code URL for image, from google charts.
setCodeLength ( integer $length ) : PHPGangsta_GoogleAuthenticator Set the code length, should be >=6.
verifyCode ( string $secret, string $code, integer $discrepancy = 1, integer | null $currentTimeSlice = null ) : boolean Check if the code is correct. This will accept codes starting from $discrepancy*30sec ago to $discrepancy*30sec from now.

Protected Methods

Method Description
_base32Decode ( $secret ) : boolean | string Helper class to decode base32.
_getBase32LookupTable ( ) : array Get array with all 32 characters for decoding from/encoding to base32.

Private Methods

Method Description
timingSafeEquals ( string $safeString, string $userString ) : boolean A timing safe equals comparison more info here: http://blog.ircmaxell.com/2014/11/its-all-about-time.html.

Method Details

_base32Decode() protected method

Helper class to decode base32.
protected _base32Decode ( $secret ) : boolean | string
$secret
return boolean | string

_getBase32LookupTable() protected method

Get array with all 32 characters for decoding from/encoding to base32.
protected _getBase32LookupTable ( ) : array
return array

createSecret() public method

16 characters, randomly chosen from the allowed base32 characters.
public createSecret ( integer $secretLength = 16 ) : string
$secretLength integer
return string

getCode() public method

Calculate the code, with given secret and point in time.
public getCode ( string $secret, integer | null $timeSlice = null ) : string
$secret string
$timeSlice integer | null
return string

getQRCodeGoogleUrl() public method

Get QR-Code URL for image, from google charts.
public getQRCodeGoogleUrl ( string $name, string $secret, string $title = null, array $params = [] ) : string
$name string
$secret string
$title string
$params array
return string

setCodeLength() public method

Set the code length, should be >=6.
public setCodeLength ( integer $length ) : PHPGangsta_GoogleAuthenticator
$length integer
return PHPGangsta_GoogleAuthenticator

verifyCode() public method

Check if the code is correct. This will accept codes starting from $discrepancy*30sec ago to $discrepancy*30sec from now.
public verifyCode ( string $secret, string $code, integer $discrepancy = 1, integer | null $currentTimeSlice = null ) : boolean
$secret string
$code string
$discrepancy integer This is the allowed time drift in 30 second units (8 means 4 minutes before or after)
$currentTimeSlice integer | null time slice if we want use other that time()
return boolean

Property Details

$_codeLength protected_oe property

protected $_codeLength