public function testAddUser()
 {
     /* check auth methods */
     $this->object->addUser("fred", "ted");
     MongoAuth::getHash("fred", "ted");
     $a2 = new MongoAdmin();
     $this->assertTrue($a2->connected);
     $a2->login("fred", "ted");
     $this->assertTrue($a2->loggedIn, json_encode($a2));
     $x = $this->object->changePassword("fred", "ted", "foobar");
     $this->assertEquals(1, $x['ok'], json_encode($x));
     $a2 = new MongoAdmin();
     $a2->login("fred", "ted");
     $this->assertFalse($a2->loggedIn);
     $a2 = new MongoAdmin();
     $a2->login("fred", "foobar");
     $this->assertTrue($a2->loggedIn);
     $this->object->deleteUser("fred");
     $a2 = new MongoAdmin();
     $a2->login("fred", "foobar");
     $this->assertFalse($a2->loggedIn);
 }
Exemple #2
0
 /**
  * Logs in to a given database.
  *
  * @param string $username  username
  * @param string $password  password
  * @param bool   $plaintext in plaintext, vs. encrypted
  *
  * @return bool if login was successful
  */
 public function login($username, $password, $plaintext = true)
 {
     return parent::login(MongoUtil::ADMIN, $username, $password, $plaintext);
 }
Exemple #3
0
 /**
  * Changes a user's password.
  *
  * @param string $username the username
  * @param string $oldpass  the old password
  * @param string $newpass  the new password
  *
  * @return array whether the change was successful
  */
 public function changePassword($username, $oldpass, $newpass)
 {
     $c = $this->db->selectCollection('system.users');
     $user = $c->findOne(array('user' => $username));
     if (!$user) {
         return array('ok' => -2.0, 'errmsg' => 'no user with username $username found');
     }
     if ($user['pwd'] == MongoAuth::getHash($username, $oldpass)) {
         $user['pwd'] = MongoAuth::getHash($username, $newpass);
         $c->update(array('user' => $username), $user);
         return array('ok' => 1.0);
     }
     return array('ok' => -1.0, 'errmsg' => 'incorrect old password');
 }