/** * Tests generateRandom */ public function testGenerateRandom() { // contains numbers 2-7 and letters A-Z in large letters, 16 chars long $this->assertRegExp('/[2-7A-Z]{16}/', GoogleAuthenticator::generateRandom()); // Can be told to make a longer secret $this->assertRegExp('/[2-7A-Z]{18}/', GoogleAuthenticator::generateRandom(18)); }
/** * Get secret token * * @access public * @return string */ public function getSecret() { if (empty($this->secret)) { $this->secret = GoogleAuthenticator::generateRandom(); } return $this->secret; }
public function totp() { $secret = GoogleAuthenticator::generateRandom(); $_SESSION['user']['totp_secret'] = $secret; $username = $this->username; $qrCode = GoogleAuthenticator::getQrCodeUrl('totp', 'GESTCOM CRIDIP ' . $username, $secret); return $qrCode; }
public function enable() { if (!Auth::check()) { return Redirect::to('login'); } $secret = GoogleAuthenticator::generateRandom(); $qr = GoogleAuthenticator::getQrCodeUrl('totp', urlencode(Config::get('login::nombreapplicacion')) . ':' . Auth::user()->email, $secret); return View::make('login::login')->with('route', 'twostep.store')->with('mainPartial', 'twoStepEnablePartial')->with('footerPartial', 'twoStepPartialEnableFooter')->with('qr', $qr)->with('secret', $secret); }
/** * Vue L'authentification à 2 facteurs */ public function totp() { $user = $this->auth->user(); if ($user->totp_key != '') { return redirect(url('profil'))->with('error', 'L\'authentification à 2 facteurs est déjà activer'); } $secret = GoogleAuthenticator::generateRandom(); $site_name = env('SITE_NAME', 'AltisPan'); $qrcode = GoogleAuthenticator::getQrCodeUrl('totp', "{$site_name} - {$user->name}", $secret); Session::put('secret', $secret); return view('users.totp', compact('qrcode')); }
/** * Enable/disable 2FA * * @access public */ public function save() { $user = $this->getUser(); $this->checkCurrentUser($user); $values = $this->request->getValues(); if (isset($values['twofactor_activated']) && $values['twofactor_activated'] == 1) { $this->user->update(array('id' => $user['id'], 'twofactor_activated' => 1, 'twofactor_secret' => GoogleAuthenticator::generateRandom())); } else { $this->user->update(array('id' => $user['id'], 'twofactor_activated' => 0, 'twofactor_secret' => '')); } // Allow the user to test or disable the feature $this->userSession->disable2FA(); $this->flash->success(t('User updated successfully.')); $this->response->redirect($this->helper->url->to('twofactor', 'index', array('user_id' => $user['id']))); }
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. */ namespace PufferPanel\Core; use ORM, Otp\GoogleAuthenticator; $klein->respond('POST', '/ajax/account/totp', function ($request, $response) use($core) { /* * Generate the TOTP Token */ $secret = GoogleAuthenticator::generateRandom(); $account = ORM::forTable('users')->findOne($core->user->getData('id')); $account->totp_secret = $secret; $account->save(); /* * Generate QR Code */ $response->body('<div class="row" id="notice_box_totp" style="display:none;"></div> <div class="row"> <div class="col-md-6"> <center><img src="' . GoogleAuthenticator::getQrCodeUrl('totp', $core->user->getData('email'), $secret) . '" /><br /><br /><code>' . $secret . '</code></center> </div> <div class="col-md-6"> <div class="alert alert-info">Please verify your TOTP settings by scanning the QR Code to the right with your phone\'s authenticator application, and then enter the 6 number code generated by the application in the box below. Press the enter key when finished.</div> <form action="#" method="post" id="totp_token_verify"> <div class="form-group">
/** * Generate secret * * @access public * @return string */ public function generateSecret() { $this->secret = GoogleAuthenticator::generateRandom(); return $this->secret; }
public function generateRandom() { return GoogleAuthenticator::generateRandom(); }