PHP Class RobThree\Auth\TwoFactorAuth

Show file Open project: RobThree/TwoFactorAuth Class Usage Examples

Public Methods

Method Description
__construct ( $issuer = null, $digits = 6, $period = 30, $algorithm = 'sha1', $qrcodeprovider = null, $rngprovider = null )
createSecret ( $bits = 80, $requirecryptosecure = true ) Create a new secret
getCode ( $secret, $time = null ) Calculate the code with given secret and point in time
getQRCodeImageAsDataUri ( $label, $secret, $size = 200 ) Get data-uri of QRCode
getQRText ( $label, $secret ) Builds a string to be encoded in a QR code
verifyCode ( $secret, $code, $discrepancy = 1, $time = null ) Check if the code is correct. This will accept codes starting from ($discrepancy * $period) sec ago to ($discrepancy * period) sec from now

Private Methods

Method Description
base32Decode ( $value )
codeEquals ( $safe, $user ) Timing-attack safe comparison of 2 codes (see http://blog.ircmaxell.com/2014/11/its-all-about-time.html)
getTime ( $time )
getTimeSlice ( $time = null, $offset )

Method Details

__construct() public method

public __construct ( $issuer = null, $digits = 6, $period = 30, $algorithm = 'sha1', $qrcodeprovider = null, $rngprovider = null )

createSecret() public method

Create a new secret
public createSecret ( $bits = 80, $requirecryptosecure = true )

getCode() public method

Calculate the code with given secret and point in time
public getCode ( $secret, $time = null )

getQRCodeImageAsDataUri() public method

Get data-uri of QRCode
public getQRCodeImageAsDataUri ( $label, $secret, $size = 200 )

getQRText() public method

Builds a string to be encoded in a QR code
public getQRText ( $label, $secret )

verifyCode() public method

Check if the code is correct. This will accept codes starting from ($discrepancy * $period) sec ago to ($discrepancy * period) sec from now
public verifyCode ( $secret, $code, $discrepancy = 1, $time = null )