Exemplo n.º 1
0
 /**
  * Test default hash generation
  */
 public function testDefaultHash()
 {
     $opts = array('cost' => 7, 'salt' => Password::salt());
     $hash = Password::hash($this->examplePassword, null, $opts);
     $this->assertNotEmpty($hash);
     $this->assertNotEquals($this->examplePassword, $hash);
     $this->assertTrue(Password::verify($this->examplePassword, $hash));
     $this->assertFalse(Password::needsRehash($hash, null, $opts));
     $info = Password::getInfo($hash);
     $this->assertEquals(Password::ALGO_BCRYPT, $info['algo']);
 }
Exemplo n.º 2
0
 /**
  * Verify password
  *
  * @param   string      $password
  * @param   boolean     $rehashEnabled
  * @return  boolean|int
  */
 public function verifyPassword($password, $rehashEnabled = false)
 {
     if (empty($this->passwordHash)) {
         return false;
     }
     $verified = Password::verify($password, $this->passwordHash);
     if ($verified && $rehashEnabled && Password::needsRehash($this->passwordHash)) {
         $this->passwordHash = Password::hash($password);
         $this->save();
     }
     return $verified;
 }