Blog Archives

Basic authentication with Zend_Auth

for one of my projects I had to create a basic login form with DB validation. this is what I came up with


$autenticar=Zend_Auth::getInstance();
$autenticar_adaptador=new Zend_Auth_Adapter_Table();
$autenticar_adaptador->setTableName('user_credentials_table)
                     ->setIdentityColumn('username')
                     ->setCredentialColumn('password')

$correo=$request->getParam('user_email');
$clave=$request->getParam('user_pass');

$autenticar_adaptador->setIdentity($correo);
$autenticar_adaptador->setCredential(md5($clave));

$valid_user=$autenticar->autenticate($autenticar_adaptador);

if($valid_user->isValid()){
$user_data=$autenticar_adaptador->getResultRowObject(array('name','user_name'),'password');
$autenticar->getStorage()->write($user_data);
$this->_redirect('protected_page');
}else{
$this->_redirect('login_form');
}

Read the rest of this entry

Advertisements