* @since Version 1.0 */ class cGoogle2FA { private $oGA; /** * Class constructor */ public function __construct() { $this->oGA = new PHPGangsta_GoogleAuthenticator(); } /** * Function to get new google authenticator secret * * @author Mareks Keišs * @category LIB cGoogle2FA * @return string - encrypted string */ public function getNewGoogleAuthSecret() { return $this->oGA->createSecret(); } /** * Function to get next google authenticator access code * * @author Mareks Keišs * @category LIB cGoogle2FA * @param string $sSecret - secret linked for user account * @return string - encrypted string */ public function getGoogleAuthCode($sSecret) { return $this->oGA->getCode($sSecret); } /** * Function to get new google authenticator secret QR code * * @author Mareks Keišs * @category LIB cGoogle2FA * @param string $sSecret - secret to be linked for user account * @param string $sUserTitle - user account string * @param string $sIssuer - issuer title * @return string - encrypted string */ public function getNewGoogleAuthSecretQRCodeLink($sSecret, $sUserTitle = '', $sIssuer = '') { // Replace all invalid symbols $sIssuer = preg_replace('/[:;\'\\"\/*-+=#$^&(){}\[\],`~§±]/i', '', $sIssuer); $sUserTitle = preg_replace('/[:;\'\\"\/*-+=#$^&(){}\[\],`~§±]/i', '', $sUserTitle); $sUserTitle = preg_replace('/ /', '_', $sUserTitle); return $this->oGA->getQRCodeGoogleUrl($sUserTitle, $sSecret, $sIssuer); } /** * Function to get new google authenticator secret QR code * * @author Mareks Keišs * @category LIB cGoogle2FA * @param string $sSecret - linked secret to user account * @param string $sCode - input code to check * @param int $iTolerance - code tolerance 1 - 30s, 2 - 1min, 8 - 4min * @return string - encrypted string */ public function verifyCode($sSecret, $sCode, $iTolerance = 1) { return $this->oGA->verifyCode($sSecret, $sCode, $iTolerance); // 2 = 2*30sec clock tolerance } }