Close #15 added two factor authentication
This commit is contained in:
37
src/User/Validator/TwoFactorCodeValidator.php
Normal file
37
src/User/Validator/TwoFactorCodeValidator.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Da\User\Validator;
|
||||
|
||||
use Da\TwoFA\Manager;
|
||||
use Da\User\Contracts\ValidatorInterface;
|
||||
use Da\User\Model\User;
|
||||
|
||||
class TwoFactorCodeValidator implements ValidatorInterface
|
||||
{
|
||||
protected $user;
|
||||
protected $code;
|
||||
protected $cycles;
|
||||
|
||||
/**
|
||||
* TwoFactorCodeValidator constructor.
|
||||
*
|
||||
* @param User $user
|
||||
* @param $code
|
||||
* @param int $cycles
|
||||
*/
|
||||
public function __construct(User $user, $code, $cycles = 0)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->code = $code;
|
||||
$this->cycles = $cycles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|int
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
$manager = new Manager();
|
||||
return $manager->setCycles($this->cycles)->verify($this->code, $this->user->auth_tf_key);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user