public function testAuthBasic() { $ok = $this->object->authenticate("testUser", "testPass"); $this->assertEquals($ok['ok'], 1, json_encode($ok)); $ok = $this->object->authenticate("testUser", "bar"); $this->assertEquals($ok['ok'], 0, json_encode($ok)); }
public function __construct($host, $port, $name, $username, $password) { try { $client = new \MongoClient("mongodb://{$host}:{$port}"); $this->db = new \MongoDB($client, $name); $this->db->authenticate($username, $password); } catch (\MongoException $e) { die('Connection failed: ' . $e->getMessage()); } }
/** * Establishes connection to database (does not check for DB sanity) * * @return boolean */ public function connect() { $this->numQueries++; try { $this->mongo = new Mongo(TeraWurflConfig::$DB_HOST, self::$CONNECTION_OPTIONS); $this->dbcon = $this->mongo->selectDB(TeraWurflConfig::$DB_SCHEMA); if (!empty(TeraWurflConfig::$DB_USER) && !empty(TeraWurflConfig::$DB_PASS)) { $this->dbcon->authenticate(TeraWurflConfig::$DB_USER, TeraWurflConfig::$DB_PASS); } } catch (Exception $e) { $this->errors[] = $e->__toString() . ', caught in ' . __CLASS__ . '::' . __METHOD__ . '()'; $this->connected = $e->getCode(); return false; } $this->mergecoll = $this->dbcon->selectCollection(self::$MERGE); $this->connected = true; return true; }
/** * Wrapper method for MongoDB::authenticate(). * * @see http://php.net/manual/en/mongodb.authenticate.php * @param string $username * @param string $password * @return array */ public function authenticate($username, $password) { return $this->mongoDB->authenticate($username, $password); }