Zend_Auth and Zend_Acl perform login authentication and permission control based on user roles. Friends in need can refer to it.
Zend_Auth_Adapter_Interface provides an interface, we need to implement it ourselves
The code is as follows:
The code is as follows | Copy code |
require_once 'Zend/Auth/Adapter/Interface .php'; class Auth implements Zend_Auth_Adapter_Interface{ private $_useraccount; private $_password; private $_db; /** * Constructor to set username and password data connection object * * @return void */ public function __construct ($useraccount,$password,$db){ $this->_useraccount = $useraccount; $this->_password = $password; $this->_db = $db; } /** */ public function authenticate() { //Authentication fails by default $authResult = array( ); ) {//Authentication If successful, the user information will be stored in the session $authResult = array( 'code' => Zend_Auth_Result::SUCCESS, 'identity' => t['name'], _Auth::getInstance( ) // Single mode -& gt; getstorage () -& gt; getnamespace (); $ _Session [$ namespace] ['role'] = $ result ['group_id']; // User group to which it belongs $_SESSION[$namespace]['userInfo'] = $result; $_SESSION[$namespace]['userInfo']['lastLoginTime'] = $result['login_time']; through// $_SESSION[$namespace]['userInfo']['password'] return new Zend_Auth_Result($authResult['code'], $authResult['identity'], $authResult['info']); } /** * User password encryption * @param $pwd Original password * @return string Encrypted password string * */ static public function encryptionType($pwd=null) { using use using with using using out through out using through off ’s ’ through ‐ return $pw's ‐ { $resArr = array(); $sysUserObj = Base_Dao_Factory::getObject('Admin_Models_User'); //Log in to a regular member account first $data = array( 'login_name ' => $this->_useraccount, 'login_pwd' => $this->encryptionType($this->_password) ); $result = $sysUserObj-> login($data); //Determine whether there is data, if so assign value if ($result) { if (!empty($result[0])) { $resArr = $result[0]; > Explanation: In the implementation code of the authenticate method, a Zend_Auth_Result object instance is returned. Looking at the source code of Zend_Auth_Result, we know that three parameters need to be passed in when instantiating:
@param int $code The result of identity authentication (For example: Zend_Auth_Result::SUCCESS)
@param mixed $identity Identifier used for identity authentication (for example: login name (Zhang San))
@param array $messages Authentication failed Reason array
Once the authentication is successful, the information is stored in the session variable.
1 2 3 4
http://www.bkjia.com/PHPjc/444673.html
www.bkjia.com
| true
http: //www.bkjia.com/PHPjc/444673.html
TechArticle
Zend_Auth and Zend_Acl are used for login authentication and permission control based on user roles. Friends who need it can refer to it. Zend_Auth_Adapter_Interface provides an interface, we need to...