Skip to content
An authentification adapter for mongodb based on the mysql adapter
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

An authentification (Zend_Auth) Adapter for use with a MongoDB (NoSQL) Database.

Here is an example howto use the adapter (it's very similar to how you use the mysql adapter), some methods have slightly different names:

# AuthController.php

public function loginAction() {

    $form = new User_Form_LoginForm();

    if ($this->_request->isPost()) {

        $formData = $this->_request->getPost();

        if ($form->isValid($formData)) {

			$formData = $form->getValues();

			$userCollection = $mongoConnection->selectCollection('user');
			$userConfiguration = Zend_Registry::get('UserConfiguration');
			// create authAdapter instance
			$authAdapter = new Chris_Auth_Adapter_MongoDB($userCollection);
			$authAdapter	->setIdentityKey('username');
			$authAdapter	->setCredentialKey('password');
			$authAdapter	->setIdentity($formData['username']);
			$authAdapter	->setCredential($formData['password']);
			$authAdapter	->setSalt($userConfiguration->authentification->password->salt);

			$result = $auth->authenticate($authAdapter);

			if ($result->isValid()) {

				$data = $authAdapter->getResultObject(null, 'password');

			} else {
				// login failed
		} else {
			// form data aint valid
	} else {
		$this->view->form = $form;


Redo the credential treatement part. Right know it's hardcoded and does only check if a salt was provided. Maybe could allow use to choose between md5 with salt and crypt, with a preference for crypt.

Feedback is welcome ;) Use the Github Issues system or visite me @

You can’t perform that action at this time.