private function generateUserHandle(NKUser $userData)
 {
     $name = preg_replace('/[^a-z0-9.]/i', '', $this->remove_plchars($userData->name()));
     $check_name = true;
     while ($check_name) {
         $find = qa_db_user_find_by_handle($name);
         if (count($find) > 0) {
             $name .= mt_rand(0, 9);
         } else {
             $check_name = false;
         }
     }
     return $name;
 }
function qa_handle_make_valid($handle, $allowuserid = null)
{
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    require_once QA_INCLUDE_DIR . 'qa-db-maxima.php';
    if (!strlen($handle)) {
        $handle = qa_lang('users/registered_user');
    }
    $handle = preg_replace('/[\\@\\+\\/]/', ' ', $handle);
    for ($attempt = 0; $attempt <= 99; $attempt++) {
        $suffix = $attempt ? ' ' . $attempt : '';
        $tryhandle = qa_substr($handle, 0, QA_DB_MAX_HANDLE_LENGTH - strlen($suffix)) . $suffix;
        $handleusers = qa_db_user_find_by_handle($tryhandle);
        if (!(count($handleusers) && (!isset($allowuserid) || array_search($allowuserid, $handleusers) === false))) {
            return $tryhandle;
        }
    }
    qa_fatal_error('Could not create a unique handle');
}
示例#3
0
$passwordsent = qa_get('ps');
if (qa_clicked('dologin')) {
    require_once QA_INCLUDE_DIR . 'qa-app-limits.php';
    if (qa_limits_remaining(null, QA_LIMIT_LOGINS)) {
        require_once QA_INCLUDE_DIR . 'qa-db-users.php';
        require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
        qa_limits_increment(null, QA_LIMIT_LOGINS);
        $inemailhandle = qa_post_text('emailhandle');
        $inpassword = qa_post_text('password');
        $inremember = qa_post_text('remember');
        $errors = array();
        if (qa_opt('allow_login_email_only') || strpos($inemailhandle, '@') !== false) {
            // handles can't contain @ symbols
            $matchusers = qa_db_user_find_by_email($inemailhandle);
        } else {
            $matchusers = qa_db_user_find_by_handle($inemailhandle);
        }
        if (count($matchusers) == 1) {
            // if matches more than one (should be impossible), don't log in
            $inuserid = $matchusers[0];
            $userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($inuserid, true));
            if (strtolower(qa_db_calc_passcheck($inpassword, $userinfo['passsalt'])) == strtolower($userinfo['passcheck'])) {
                // login and redirect
                require_once QA_INCLUDE_DIR . 'qa-app-users.php';
                qa_set_logged_in_user($inuserid, $userinfo['handle'], $inremember ? true : false);
                $topath = qa_get('to');
                if (isset($topath)) {
                    qa_redirect_raw(qa_path_to_root() . $topath);
                } elseif ($passwordsent) {
                    qa_redirect('account');
                } else {
function qa_handle_make_valid($handle)
{
    require_once QA_INCLUDE_DIR . 'qa-util-string.php';
    require_once QA_INCLUDE_DIR . 'qa-db-maxima.php';
    require_once QA_INCLUDE_DIR . 'qa-db-users.php';
    if (!strlen($handle)) {
        $handle = qa_lang('users/registered_user');
    }
    $handle = preg_replace('/[\\@\\+\\/]/', ' ', $handle);
    for ($attempt = 0; $attempt <= 99; $attempt++) {
        $suffix = $attempt ? ' ' . $attempt : '';
        $tryhandle = qa_substr($handle, 0, QA_DB_MAX_HANDLE_LENGTH - strlen($suffix)) . $suffix;
        $filtermodules = qa_load_modules_with('filter', 'filter_handle');
        foreach ($filtermodules as $filtermodule) {
            $filtermodule->filter_handle($tryhandle, null);
        }
        // filter first without worrying about errors, since our goal is to get a valid one
        $haderror = false;
        foreach ($filtermodules as $filtermodule) {
            $error = $filtermodule->filter_handle($tryhandle, null);
            // now check for errors after we've filtered
            if (isset($error)) {
                $haderror = true;
            }
        }
        if (!$haderror) {
            $handleusers = qa_db_user_find_by_handle($tryhandle);
            if (!count($handleusers)) {
                return $tryhandle;
            }
        }
    }
    qa_fatal_error('Could not create a valid and unique handle from: ' . $handle);
}
示例#5
0
 function core_login($username, $password, $remember = false)
 {
     require_once QA_INCLUDE_DIR . 'qa-app-limits.php';
     if (qa_user_limits_remaining(QA_LIMIT_LOGINS)) {
         require_once QA_INCLUDE_DIR . 'qa-db-users.php';
         require_once QA_INCLUDE_DIR . 'qa-db-selects.php';
         $errors = array();
         if (qa_opt('allow_login_email_only') || strpos($username, '@') !== false) {
             // handles can't contain @ symbols
             $matchusers = qa_db_user_find_by_email($username);
         } else {
             $matchusers = qa_db_user_find_by_handle($username);
         }
         if (count($matchusers) == 1) {
             // if matches more than one (should be impossible), don't log in
             $inuserid = $matchusers[0];
             $userinfo = qa_db_select_with_pending(qa_db_user_account_selectspec($inuserid, true));
             if (strtolower(qa_db_calc_passcheck($password, $userinfo['passsalt'])) == strtolower($userinfo['passcheck'])) {
                 // login
                 require_once QA_INCLUDE_DIR . 'qa-app-users.php';
                 qa_set_logged_in_user($inuserid, $userinfo['handle'], $remember ? true : false);
                 return $userinfo;
             } else {
                 $this->error = new IXR_Error(1512, qa_lang('users/password_wrong'));
             }
         } else {
             $this->error = new IXR_Error(1512, qa_lang('users/user_not_found'));
         }
     } else {
         $this->error = new IXR_Error(1512, qa_lang('users/login_limit'));
     }
     qa_limits_increment(null, QA_LIMIT_LOGINS);
     // log on failure
     return false;
 }