Rediska

Follow me on twitter…

Zend_Auth adapter

If you want to use Redis to store users data, you need to include Redis Zend_Auth adapter for authorization logic:

<?php

$auth = Zend_Auth::getInstance();

/**
 * userIdKey               - Redis key where you store relation between login and id. * replaced to identity (login)
 * userDataKey             - Redis key where you store user data
 * credentialAttributeName - Name of credential (password) attribute in user data
 * userDataIsArray         - Set true if you store user data in associative array
 * identity                - User identity (login) for authorization
 * credential              - User credintial (password) for authorization
 * rediska                 - Rediska instance.
 */
$options = array(
    'userIdKey'   => 'user_id_*',
    'userdatakey' => 'user_*',
);
$adapter = new Rediska_Zend_Auth_Adapter_Redis($options);

// Set login and password
$adapter->setIdentity('john')
        ->setCredential('god');

// Authorization
$result = $auth->authenticate($adapter);
if ($result->isValid()) {
    echo 'Success';
} else {
    echo 'Login or password invalid';
}

?>

If there's no Rediska instance in options, adapter will use default instance (initialized from application.ini with default options).

Comments