Advertisement
mfiresheets

ZF Training Authentication

Sep 5th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. <?php
  2.  
  3. class AuthController extends Zend_Controller_Action
  4. {
  5.  
  6.     public function init()
  7.     {
  8.         $db = Zend_Db::factory('Pdo_Mysql', array(
  9.             'host'     => 'localhost',
  10.             'username' => 'test',
  11.             'password' => 'test',
  12.             'dbname'   => 'test',
  13.         ));
  14.         Zend_Db_Table::setDefaultAdapter($db);
  15.     }
  16.  
  17.     public function indexAction()
  18.     {
  19.         // action body
  20.     }
  21.  
  22.     public function loginAction()
  23.     {
  24.         $config  = $this->getInvokeArg('bootstrap')->getOption('auth');
  25.         $salt    = $config['salt'];
  26.         $auth = new Zend_Auth_Adapter_DbTable(
  27.             Zend_Db_Table::getDefaultAdapter(),
  28.             'users',
  29.             'email',
  30.             'password',
  31.             'SHA1(?)'
  32.         );
  33.         $auth->setIdentity($this->getRequest()->getPost('email'))
  34.              ->setCredential($this->getRequest()->getPost('password') . $salt);
  35.         $result = $auth->authenticate();
  36.         echo $result->isValid();
  37.     }
  38.  
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement