diff --git a/.idea/google2fa-laravel-forked.iml b/.idea/google2fa-laravel-forked.iml new file mode 100644 index 0000000..b418948 --- /dev/null +++ b/.idea/google2fa-laravel-forked.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..8f2f608 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..847cdbf --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Google2FA.php b/src/Google2FA.php index a65a8ce..1d237a8 100644 --- a/src/Google2FA.php +++ b/src/Google2FA.php @@ -202,7 +202,10 @@ protected function passwordExpired() protected function twoFactorAuthStillValid() { return - (bool) $this->sessionGet(Constants::SESSION_AUTH_PASSED, false) && + ( + (bool) $this->sessionGet(Constants::SESSION_AUTH_PASSED, false) || + ( $this->config('remember') && $this->getUser()->{$this->config('remember_column')} && ( Carbon::now() <= (new Carbon($this->getUser()->{$this->config('remember_column')}))->addMinutes($this->config('lifetime')) ) ) + ) && !$this->passwordExpired(); } @@ -223,6 +226,12 @@ public function login() { $this->sessionPut(Constants::SESSION_AUTH_PASSED, true); + if (isset(\Cookie::get()[\Auth::getRecallerName()])) { + $user = $this->getUser(); + $user->{$this->config('remember_column')} = Carbon::now(); + $user->save(); + } + $this->updateCurrentAuthTime(); } @@ -232,6 +241,8 @@ public function login() public function logout() { $user = $this->getUser(); + $user->{$this->config('remember_column')} = null; + $user->save(); $this->sessionForget(); diff --git a/src/config/config.php b/src/config/config.php index d9b0ba5..f7ecc88 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -14,6 +14,20 @@ */ 'lifetime' => 0, // 0 = eternal + /* + * Make persistent by using a database column. + * + * In case you need the lifetime to be greater than the lifespan of your current session. (ex: used for remember_me) + */ + 'remember' => true, + + /* + *User's table column to use for persistent 2FA. + * + * Column type should be timestamp. + */ + 'remember_column' => 'google2fa_remember', + /* * Renew lifetime at every new request. */