public function testSecret()
 {
     $twofactorAdapter = new twofactorAdapter();
     $this->assertTrue($twofactorAdapter->check($twofactorAdapter->getCode()));
     $twofactorAdapter2 = new twofactorAdapter();
     $twofactorAdapter2->setSecret($twofactorAdapter->getSecret());
     $this->assertEquals($twofactorAdapter2->getSecret(), $twofactorAdapter->getSecret());
     $this->assertTrue($twofactorAdapter2->check($twofactorAdapter->getCode()));
     $this->assertEquals($twofactorAdapter2->getCode(), $twofactorAdapter->getCode());
     $twofactorAdapter2->setSecret("XVQ2UIGO75XRUKJO");
     $this->assertNotEquals($twofactorAdapter2->getSecret(), $twofactorAdapter->getSecret());
     $this->assertFalse($twofactorAdapter2->check($twofactorAdapter->getCode()));
     $this->assertTrue($twofactorAdapter2->check($twofactorAdapter2->getCode()));
     $this->assertNotEquals($twofactorAdapter2->getCode(), $twofactorAdapter->getCode());
 }
Exemplo n.º 2
0
 /**
  * CAUTION this method uses cookie, it must be called before any print
  * this method checks code and performs login
  * this method perform redirect if the code is correct, after setting the cookie
  * @param string $code
  * @return bool true if the code is corret
  */
 public function checkCode($code)
 {
     $res = $this->twofactorAdapter->check($code);
     if ($res) {
         setcookie('twofactorDir-' . $this->dir, $this->cookieCode, 0, "/");
         self::redirect();
     }
     return $res;
 }