<?php include_once __DIR__ . "/../lib/Google/Authenticator/FixedBitNotation.php"; include_once __DIR__ . "/../lib/Google/Authenticator/GoogleAuthenticator.php"; $secret = 'XVQ2UIGO75XRUKJO'; $time = floor(time() / 30); $code = "846474"; $g = new \Google\Authenticator\GoogleAuthenticator(); print "Current Code is: "; print $g->getCode($secret); print "\n"; print "Check if {$code} is valid: "; if ($g->checkCode($secret, $code)) { print "YES \n"; } else { print "NO \n"; } $secret = $g->generateSecret(); print "Get a new Secret: {$secret} \n"; print "The QR Code for this secret (to scan with the Google Authenticator App: \n"; print $g->getURL('chregu', 'example.org', $secret); print "\n";
/** * Finds a user by the given credentials. */ public function confirmUserByCredentials($user, array $credentials) { if (!$user->mfa_enabled) { return $user; } if (!$user->mfa_secret) { throw new Exception('User has not generated an MFA code.'); } require_once __DIR__ . "/../vendor/sonata-project/google-authenticator/lib/FixedBitNotation.php"; require_once __DIR__ . "/../vendor/sonata-project/google-authenticator/lib/GoogleAuthenticator.php"; $g = new \Google\Authenticator\GoogleAuthenticator(); $code = $g->getCode($user->mfa_secret); if ($credentials['code'] != $code) { throw new Exception('A user was not found with the given credentials.'); } return $user; }