Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 101... Línea 101...
101
    }
101
    }
102
    return !empty($CFG->cookiesecure);
102
    return !empty($CFG->cookiesecure);
103
}
103
}
Línea 104... Línea 104...
104
 
104
 
105
/**
105
/**
106
 * Sets a moodle cookie with a weakly encrypted username
106
 * Sets a Moodle cookie with an encrypted username
107
 *
107
 *
108
 * @param string $username to encrypt and place in a cookie, '' means delete current cookie
-
 
109
 * @return void
108
 * @param string $username to encrypt and place in a cookie, '' means delete current cookie
110
 */
109
 */
111
function set_moodle_cookie($username) {
110
function set_moodle_cookie($username) {
Línea 112... Línea 111...
112
    global $CFG;
111
    global $CFG;
Línea 132... Línea 131...
132
    // Delete old cookie.
131
    // Delete old cookie.
133
    setcookie($cookiename, '', time() - HOURSECS, $CFG->sessioncookiepath, $CFG->sessioncookiedomain, $cookiesecure, $CFG->cookiehttponly);
132
    setcookie($cookiename, '', time() - HOURSECS, $CFG->sessioncookiepath, $CFG->sessioncookiedomain, $cookiesecure, $CFG->cookiehttponly);
Línea 134... Línea 133...
134
 
133
 
135
    if ($username !== '') {
134
    if ($username !== '') {
136
        // Set username cookie for 60 days.
135
        // Set username cookie for 60 days.
-
 
136
        setcookie($cookiename, \core\encryption::encrypt($username), time() + (DAYSECS * 60), $CFG->sessioncookiepath,
137
        setcookie($cookiename, rc4encrypt($username), time() + (DAYSECS * 60), $CFG->sessioncookiepath, $CFG->sessioncookiedomain, $cookiesecure, $CFG->cookiehttponly);
137
            $CFG->sessioncookiedomain, $cookiesecure, $CFG->cookiehttponly);
138
    }
138
    }
Línea 139... Línea 139...
139
}
139
}
140
 
140
 
141
/**
141
/**
142
 * Gets a moodle cookie with a weakly encrypted username
142
 * Gets a Moodle cookie with an encrypted username
143
 *
143
 *
144
 * @return string username
144
 * @return string username
145
 */
145
 */
Línea 154... Línea 154...
154
        return '';
154
        return '';
155
    }
155
    }
Línea 156... Línea 156...
156
 
156
 
Línea 157... Línea -...
157
    $cookiename = 'MOODLEID1_'.$CFG->sessioncookie;
-
 
158
 
-
 
159
    if (empty($_COOKIE[$cookiename])) {
157
    $cookiename = 'MOODLEID1_'.$CFG->sessioncookie;
160
        return '';
158
 
161
    } else {
159
    try {
162
        $username = rc4decrypt($_COOKIE[$cookiename]);
160
        $username = \core\encryption::decrypt($_COOKIE[$cookiename] ?? '');
163
        if ($username === 'guest' or $username === 'nobody') {
161
        if ($username === 'guest' || $username === 'nobody') {
164
            // backwards compatibility - we do not set these cookies any more
162
            // backwards compatibility - we do not set these cookies any more
165
            $username = '';
163
            $username = '';
-
 
164
        }
-
 
165
        return $username;
166
        }
166
    } catch (\moodle_exception $ex) {
167
        return $username;
167
        return '';