本文整理汇总了PHP中BaseUser::hashPassword方法的典型用法代码示例。如果您正苦于以下问题:PHP BaseUser::hashPassword方法的具体用法?PHP BaseUser::hashPassword怎么用?PHP BaseUser::hashPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseUser
的用法示例。
在下文中一共展示了BaseUser::hashPassword方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: login
/**
* Logs an user in the application based on his
* username and email
*
* @param string $username
* @param string $password
* @param boolean $remember
* @access public
* @return void
*/
public function login($username, $password, $remember = FALSE)
{
// adapter cfg
$adapter = new Zend_Auth_Adapter_DbTable($this->_db);
$adapter->setTableName($this->_name);
$adapter->setIdentityColumn('username');
$adapter->setCredentialColumn('password');
// checking credentials
$adapter->setIdentity($username);
$adapter->setCredential(BaseUser::hashPassword($password));
try {
$result = $adapter->authenticate();
} catch (Zend_Auth_Adapter_Exception $e) {
App_Logger::log(sprintf("Exception catched while login: %s", $e->getMessage()), Zend_Log::ERR);
return FALSE;
}
if ($result->isValid()) {
// get the user row
$loggedUser = $adapter->getResultRowObject(NULL, 'password');
//Check if the account has been closed
if ($loggedUser->deleted) {
return NULL;
}
// clear the existing data
$auth = Zend_Auth::getInstance();
$auth->clearIdentity();
if (!empty($loggedUser->id)) {
switch (CURRENT_MODULE) {
case 'frontend':
$userModel = new User();
$user = $userModel->findById($loggedUser->id);
$user->get('group');
$session = new stdClass();
foreach (get_object_vars($loggedUser) as $k => $v) {
$session->{$k} = $v;
}
$session->group->name = $user->get('group')->name;
break;
case 'backoffice':
$userModel = new BackofficeUser();
$user = $userModel->findById($loggedUser->id);
$user->groups = $user->findManyToManyRowset('Group', 'BackofficeUserGroup');
$user->group = $user->groups[0];
$session = new stdClass();
foreach (get_object_vars($loggedUser) as $k => $v) {
$session->{$k} = $v;
}
$session->group->name = $user->group->name;
break;
}
$auth->getStorage()->write($session);
}
$this->update(array('last_login' => new Zend_Db_Expr('NOW()')), $this->_db->quoteInto('id = ?', $user->id));
if ($rememberMe) {
Zend_Session::rememberMe(App_DI_Container::get('ConfigObject')->session->remember_me->lifetime);
} else {
Zend_Session::forgetMe();
}
return TRUE;
} else {
return FALSE;
}
}