for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Controller\Component;
use Cake\Controller\Component;
use Cake\ORM\TableRegistry;
class TwoFactorAuthComponent extends Component
{
/**
* Check if the current user session is the same as the saved session.
*
* @param int $user The user id.
* @return bool
*/
public function isAuthorized($user)
$session = $this->request->clientIp() . $this->request->header('User-Agent') . gethostbyaddr($this->request->clientIp());
$this->UsersTwoFactorAuth = TableRegistry::get('UsersTwoFactorAuth');
UsersTwoFactorAuth
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
$tfa = $this->UsersTwoFactorAuth
->find()
->where([
'user_id' => $user
])
->first();
if (is_null($tfa)) {
return false;
}
return $tfa->session === $session;
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: