Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php google authenauthenticator

composer require sonata-project/google-authenticator or https://github.com/sonata-project/GoogleAuthenticator

include_once 'vendor/sonata-project/google-authenticator/src/FixedBitNotation.php';
include_once 'vendor/sonata-project/google-authenticator/src/GoogleAuthenticatorInterface.php';
include_once 'vendor/sonata-project/google-authenticator/src/GoogleAuthenticator.php';
include_once 'vendor/sonata-project/google-authenticator/src/GoogleQrUrl.php';
 
$g = new GoogleAuthenticatorGoogleAuthenticator();
$secret = 'XVQ2UIGO75XRUKJO';
//Optionally, you can use $g->generateSecret() to generate your secret
//$secret = $g->generateSecret();
 
//the "getUrl" method takes as a parameter: "username", "host" and the key "secret"
echo '<img src="'.$g->getURL('user', 'mywebsite.com', $secret).'" />';
 
$secret = 'XVQ2UIGO75XRUKJO';
 
$code = '010989'; //6-digit code generated by Google Authenticator app
 
if($g->checkCode($secret, $code)){
	echo 'Authorized!';
}
else{
	echo 'Incorrect or expired code!';
}

Source by www.rafaelwendel.com #
 
PREVIOUS NEXT
Tagged: #php #google #authenauthenticator
ADD COMMENT
Topic
Name
4+2 =