本文整理汇总了PHP中BackendAuthentication::getEncryptedPassword方法的典型用法代码示例。如果您正苦于以下问题:PHP BackendAuthentication::getEncryptedPassword方法的具体用法?PHP BackendAuthentication::getEncryptedPassword怎么用?PHP BackendAuthentication::getEncryptedPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BackendAuthentication
的用法示例。
在下文中一共展示了BackendAuthentication::getEncryptedPassword方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loginUser
/**
* Login the user with the given credentials.
* Will return a boolean that indicates if the user is logged in.
*
* @return bool
* @param string $login The users login.
* @param string $password The password provided by the user.
*/
public static function loginUser($login, $password)
{
// redefine
$login = (string) $login;
$password = (string) $password;
// init vars
$db = BackendModel::getDB(true);
// fetch the encrypted password
$passwordEncrypted = BackendAuthentication::getEncryptedPassword($login, $password);
// check in database (is the user active and not deleted, are the email and password correct?)
$userId = (int) $db->getVar('SELECT u.id
FROM users AS u
WHERE u.email = ? AND u.password = ? AND u.active = ? AND u.deleted = ?
LIMIT 1', array($login, $passwordEncrypted, 'Y', 'N'));
// not 0 = valid user!
if ($userId !== 0) {
// cleanup old sessions
self::cleanupOldSessions();
// build the session array (will be stored in the database)
$session = array();
$session['user_id'] = $userId;
$session['secret_key'] = BackendAuthentication::getEncryptedString(SpoonSession::getSessionId(), $userId);
$session['session_id'] = SpoonSession::getSessionId();
$session['date'] = BackendModel::getUTCDate();
// insert a new row in the session-table
$db->insert('users_sessions', $session);
// store some values in the session
SpoonSession::set('backend_logged_in', true);
SpoonSession::set('backend_secret_key', $session['secret_key']);
// return result
return true;
} else {
// reset values for invalid users. We can't destroy the session because session-data can be used on the site.
SpoonSession::set('backend_logged_in', false);
SpoonSession::set('backend_secret_key', '');
// return result
return false;
}
}