Ejemplo n.º 1
0
 /**
  * Check if the password passed is correct. CAUTION: the method already makes the md5 hash (using salt)
  * @param string $password unencrypted password
  * @return bool true if the password is correct, else false
  * @throws UsersManagementException when user is not valid
  */
 public function checkCorrectPassword($password)
 {
     $this->checkUser();
     $password = $this->usersManagement->getOperations()->getEscapedString($password);
     $passwordDb = $this->usersManagement->getOperations()->getValue("password", "id = " . $this->id);
     if ($passwordDb == $this->usersManagement->encrypt($password)) {
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 2
0
 public function testGetterSetter()
 {
     $db = (require __DIR__ . "/config.php");
     $connection = new Mysqltcs($db['host'], $db['user'], $db['psw'], $db['db']);
     $usersManagement = new UsersManagement($connection, $db['tables']['users']);
     $this->assertEquals($connection, $usersManagement->getConnection());
     $connection2 = clone $connection;
     $this->assertNotEquals($connection, $connection2);
     $usersManagement->setConnection($connection2);
     $this->assertEquals($connection2, $usersManagement->getConnection());
     $this->assertEquals($db['tables']['users'], $usersManagement->getUsersTable());
     $thrown = false;
     try {
         $usersManagement->setUsersTable("err");
     } catch (UsersManagementException $e) {
         $thrown = true;
     }
     $this->assertTrue($thrown);
     $thrown = false;
     try {
         $usersManagement->setUsersTable($db['tables']['users']);
     } catch (UsersManagementException $e) {
         $thrown = true;
     }
     $this->assertFalse($thrown);
     $this->assertEquals($db['tables']['users'], $usersManagement->getUsersTable());
     $this->assertEquals($db['tables']['users'], $usersManagement->getOperations()->getDefaultFrom());
     $this->assertEquals("thecsea", $usersManagement->getSalt());
     $usersManagement->setSalt("test");
     $this->assertEquals("test", $usersManagement->getSalt());
     $psw1 = $usersManagement->encrypt("psw");
     $usersManagement = new UsersManagement($connection, $db['tables']['users'], "test2");
     $this->assertEquals("test2", $usersManagement->getSalt());
     $psw2 = $usersManagement->encrypt("psw");
     $this->assertNotEquals($psw1, $psw2);
     $this->assertNotEquals($psw1, $usersManagement->hash("psw"));
     $this->assertNotEquals($psw2, $usersManagement->hash("psw"));
     $usersManagement->setSalt("");
     $psw3 = $usersManagement->encrypt("psw");
     $this->assertNotEquals($psw3, $psw2);
     $this->assertEquals($usersManagement->hash("psw"), $psw3);
 }