当前位置: 首页>>代码示例>>PHP>>正文


PHP UserTable::getRandomPassword方法代码示例

本文整理汇总了PHP中CB\Database\Table\UserTable::getRandomPassword方法的典型用法代码示例。如果您正苦于以下问题:PHP UserTable::getRandomPassword方法的具体用法?PHP UserTable::getRandomPassword怎么用?PHP UserTable::getRandomPassword使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CB\Database\Table\UserTable的用法示例。


在下文中一共展示了UserTable::getRandomPassword方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sendNewPass

function sendNewPass($option)
{
    global $_CB_framework, $ueConfig, $_PLUGINS, $_POST;
    $loginType = isset($ueConfig['login_type']) ? (int) $ueConfig['login_type'] : 0;
    if ($loginType == 4) {
        cbRedirect($_CB_framework->viewUrl('done', false), CBTxt::Th('UE_NOT_AUTHORIZED', 'You are not authorized to view this page!'), 'error');
        return;
    }
    // simple spoof check security
    checkCBPostIsHTTPS();
    cbSpoofCheck('lostPassForm');
    cbRegAntiSpamCheck();
    $liveSite = $_CB_framework->getCfg('live_site');
    $usernameExists = $loginType != 2;
    // ensure no malicous sql gets past
    $checkusername = trim(cbGetParam($_POST, 'checkusername', ''));
    $confirmEmail = trim(cbGetParam($_POST, 'checkemail', ''));
    $_PLUGINS->loadPluginGroup('user');
    $_PLUGINS->trigger('onStartNewPassword', array(&$checkusername, &$confirmEmail));
    if ($_PLUGINS->is_errors()) {
        cbRedirect($_CB_framework->viewUrl('lostpassword', false), $_PLUGINS->getErrorMSG(), 'error');
        return;
    }
    $checkusername = stripslashes($checkusername);
    $confirmEmail = stripslashes($confirmEmail);
    $res = false;
    $error = null;
    if ($usernameExists && $confirmEmail != '' && !$checkusername) {
        $user = new UserTable();
        if (!$user->loadByEmail($confirmEmail)) {
            cbRedirect($_CB_framework->viewUrl('lostpassword', false), CBTxt::Th('UE_EMAIL_DOES_NOT_EXISTS_ON_SITE', "The email '[email]' does not exist on this site.", array('[email]' => htmlspecialchars($confirmEmail))), 'error');
        }
        $message = str_replace('\\n', "\n", sprintf(CBTxt::T('UE_USERNAMEREMINDER_MSG', 'Hello,\\nA username reminder has been requested for your %s account.\\n\\nYour username is: %s\\n\\nTo log in to your account, click on the link below:\\n%s\\n\\nThank you.\\n'), $_CB_framework->getCfg('sitename'), $user->username, $liveSite));
        /*
        'Hello,\n'
        .'A username reminder has been requested for your %s account.\n\n'
        .'Your username is: %s\n\n'
        .'To log in to your account, click on the link below:\n'
        .'%s\n\n'
        .'Thank you.\n'
        */
        $subject = sprintf(CBTxt::T('UE_USERNAMEREMINDER_SUB', 'Username reminder for %s'), $user->username);
        $_PLUGINS->trigger('onBeforeUsernameReminder', array($user, &$subject, &$message));
        if ($_PLUGINS->is_errors()) {
            cbRedirect($_CB_framework->viewUrl('lostpassword', false), $_PLUGINS->getErrorMSG(), 'error');
            return;
        }
        $cbNotification = new cbNotification();
        $res = $cbNotification->sendFromSystem($user->id, $subject, $message);
        $error = $cbNotification->errorMSG;
        $_PLUGINS->trigger('onAfterUsernameReminder', array($user, &$res));
        if ($res) {
            cbRedirect($_CB_framework->viewUrl('done', false), sprintf(CBTxt::Th('UE_USERNAME_REMINDER_SENT', 'Username reminder sent to your email address %s. Please check your email (and if needed your spambox too)!'), htmlspecialchars($confirmEmail)));
        } else {
            cbRedirect($_CB_framework->viewUrl('done', false), $error ? CBTxt::Th('SENDING_EMAIL_FAILED_ERROR_ERROR', 'Sending Email Failed! Error: [error]', array('[error]' => $error)) : CBTxt::Th('UE_EMAIL_SENDING_ERROR', 'Error sending email'), 'error');
        }
    } elseif ($confirmEmail != '') {
        $user = new UserTable();
        if ($usernameExists) {
            $foundUser = $user->loadByUsername($checkusername);
            if ($foundUser && cbutf8_strtolower($user->email) != cbutf8_strtolower($confirmEmail)) {
                $foundUser = false;
            }
        } else {
            $foundUser = $user->loadByEmail($confirmEmail);
        }
        if (!$foundUser) {
            cbRedirect($_CB_framework->viewUrl('lostpassword', false), CBTxt::Th('ERROR_PASS', 'Sorry, no corresponding user was found'), 'error');
        }
        $resetTime = (int) $_CB_framework->getCfg('reset_time');
        $resetCount = (int) $_CB_framework->getCfg('reset_count');
        $hoursSinceLastReset = ($_CB_framework->getUTCNow() - (int) $_CB_framework->getUTCTimestamp($user->lastResetTime)) / 3600;
        if ($hoursSinceLastReset > $resetTime) {
            $user->lastResetTime = $_CB_framework->getUTCDate();
            $user->resetCount = 1;
        } else {
            $user->resetCount = $user->resetCount + 1;
        }
        if ($resetCount && $user->resetCount > $resetCount) {
            cbRedirect($_CB_framework->viewUrl('lostpassword', false), CBTxt::Th('EXCEEDED_MAXIMUM_PASSWORD_RESETS', 'You have exceeded the maximum number of password resets allowed. Please try again in %%COUNT%% hours.|You have exceeded the maximum number of password resets allowed. Please try again in 1 hour.', array('%%COUNT%%' => $resetTime)), 'error');
        }
        $newpass = $user->getRandomPassword();
        $message = str_replace('\\n', "\n", sprintf(CBTxt::T('UE_NEWPASS_MSG', 'The user account %s has this email associated with it.\\nA web user from %s has just requested that a new password be sent.\\n\\nYour New Password is: %s\\n\\nIf you didn\'t ask for this, don\'t worry. You are seeing this message, not them. If this was an error just log in with your new password and then change your password to what you would like it to be.'), $user->username, $liveSite, $newpass));
        /*
        'The user account %s has this email associated with it.\n'
        .'A web user from %s has just requested that a new password be sent.\n\n'
        .'Your New Password is: %s\n\n'
        .'If you didn\'t ask for this, don\'t worry. You are seeing this message, not them. If this was an error just log in with your new password and then change your password to what you would like it to be.'
        */
        $subject = sprintf(CBTxt::T('UE_NEWPASS_SUB', 'New password for: %s'), $user->username);
        $_PLUGINS->trigger('onBeforeNewPassword', array($user, &$newpass, &$subject, &$message));
        if ($_PLUGINS->is_errors()) {
            cbRedirect($_CB_framework->viewUrl('lostpassword', false), $_PLUGINS->getErrorMSG(), 'error');
        }
        $_PLUGINS->trigger('onNewPassword', array($user, $newpass));
        $storeValues = array('password' => $newpass, 'lastResetTime' => $user->lastResetTime, 'resetCount' => $user->resetCount);
        if (!$user->storeDatabaseValues($storeValues)) {
            cbRedirect($_CB_framework->viewUrl('lostpassword', false), $user->getError(), 'error');
        } else {
            $cbNotification = new cbNotification();
//.........这里部分代码省略.........
开发者ID:ankaau,项目名称:GathBandhan,代码行数:101,代码来源:comprofiler.php


注:本文中的CB\Database\Table\UserTable::getRandomPassword方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。