當前位置: 首頁>>代碼示例>>PHP>>正文


PHP BackendAuthentication::getEncryptedPassword方法代碼示例

本文整理匯總了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;
        }
    }
開發者ID:netconstructor,項目名稱:forkcms,代碼行數:47,代碼來源:authentication.php


注:本文中的BackendAuthentication::getEncryptedPassword方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。