Google2Fa ready to upload
This commit is contained in:
parent
e3495be8b8
commit
73e38a006e
127 changed files with 2637 additions and 589 deletions
105
app/Services/MyGoogle2FA.php
Normal file
105
app/Services/MyGoogle2FA.php
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
namespace App\Services;
|
||||
|
||||
use Google2FA;
|
||||
|
||||
class MyGoogle2FA
|
||||
{
|
||||
private $fileName = 'google2fasecret.key';
|
||||
|
||||
private $name = 'mein.sterntours.de';
|
||||
|
||||
private $email = '';
|
||||
|
||||
private $secretKey;
|
||||
|
||||
private $keySize = 32;
|
||||
|
||||
private $keyPrefix = '';
|
||||
|
||||
private $inlineUrl = '';
|
||||
|
||||
private $valid = '';
|
||||
|
||||
private $user = null;
|
||||
|
||||
|
||||
public function init($user){
|
||||
$this->name = str_replace('https://', '', config('app.url'));
|
||||
$this->user = $user;
|
||||
$this->email = $user->email;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function generate()
|
||||
{
|
||||
$this->generateSecretKey();
|
||||
$this->inlineUrl = $this->getQRCodeInline();
|
||||
}
|
||||
|
||||
public function check2Fa($code)
|
||||
{
|
||||
if(!$this->getSecretKey()){
|
||||
return false;
|
||||
}
|
||||
$this->valid = $this->validateInput($code);
|
||||
return $this->valid;
|
||||
}
|
||||
|
||||
public function getBy($key){
|
||||
return isset($this->{$key}) ? $this->{$key} : '';
|
||||
}
|
||||
|
||||
private function getQRCodeInline()
|
||||
{
|
||||
return Google2FA::getQRCodeInline(
|
||||
$this->name,
|
||||
$this->email,
|
||||
$this->secretKey
|
||||
);
|
||||
}
|
||||
private function getSecretKey()
|
||||
{
|
||||
if (! $this->secretKey = $this->getStoredKey())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return $this->secretKey;
|
||||
}
|
||||
|
||||
private function generateSecretKey()
|
||||
{
|
||||
if (! $this->secretKey = $this->getStoredKey())
|
||||
{
|
||||
$this->secretKey = Google2FA::generateSecretKey($this->keySize, $this->keyPrefix);
|
||||
$this->user->secret_key = $this->secretKey;
|
||||
$this->user->save();
|
||||
}
|
||||
return $this->secretKey;
|
||||
}
|
||||
|
||||
private function getStoredKey()
|
||||
{
|
||||
// No need to read it from disk it again if we already have it
|
||||
if ($this->secretKey)
|
||||
{
|
||||
return $this->secretKey;
|
||||
}
|
||||
if(! $this->user->secret_key){
|
||||
return null;
|
||||
}
|
||||
return $this->user->secret_key;
|
||||
}
|
||||
|
||||
private function validateInput($code)
|
||||
{
|
||||
// Verify the code
|
||||
return Google2FA::verifyKey($this->secretKey, $code);
|
||||
}
|
||||
|
||||
public static function logout()
|
||||
{
|
||||
(new AuthGoogle2FA(request()))->logout();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue