two factor authentication essental elements

This commit is contained in:
Andy Miller
2017-08-25 16:20:57 -06:00
parent c2f81fd26d
commit 8658466e8d
322 changed files with 5904 additions and 892 deletions

View File

@@ -27,6 +27,7 @@ use RocketTheme\Toolbox\Session\Session;
use Symfony\Component\Yaml\Yaml;
use Composer\Semver\Semver;
use PicoFeed\Reader\Reader;
use RobThree\Auth\TwoFactorAuth;
define('LOGIN_REDIRECT_COOKIE', 'grav-login-redirect');
@@ -377,6 +378,17 @@ class Admin
$action = [];
if ($user->authorize('admin.login')) {
$twofa_admin_enabled = $this->grav['config']->get('plugins.admin.twofa_enabled', false);
if ($twofa_admin_enabled && isset($user->twofa_enabled) && $user->twofa_enabled == true) {
$twofa = $this->get2FA();
$secret = isset($user->twofa_secret) ? $user->twofa_secret : null;
if (!(isset($data['2fa_code']) && $data['2fa_code'] == $twofa->getCode($secret))) {
return false;
}
}
$this->user = $this->session->user = $user;
/** @var Grav $grav */
@@ -1709,4 +1721,9 @@ class Admin
return $pagesWithFiles;
}
public function get2FA()
{
return new TwoFactorAuth($this->grav['config']->get('site.title'));
}
}