/** * @covers Veles\Model\User::getHash */ public function testGetHash() { $expected = null; $actual = $this->object->getHash(); $msg = 'User::getHash() returns wrong result!'; $this->assertSame($expected, $actual, $msg); $expected = '$2a$07$usesomesillystringforeGlOaUExBSD9HxuEYk2ZFaeDhggU716O'; $db_result = ['id' => 1, 'email' => '*****@*****.**', 'hash' => $expected, 'group' => UsrGroup::GUEST, 'last_login' => 'string']; $adapter = $this->getMockBuilder('\\Veles\\DataBase\\Adapters\\PdoAdapter')->setMethods(['row'])->getMock(); $adapter->expects($this->once())->method('row')->willReturn($db_result); Db::setAdapter($adapter); $this->object->getById(1); $actual = $this->object->getHash(); $this->assertSame($expected, $actual, $msg); }
/** * User password check in ajax-authentication * * @param User $user User * @param string $password Password retrieved through ajax * @return bool */ public static function check(User $user, $password) { return $user->getHash() === crypt($password, $user->getHash()); }