From f8adbd6a02f69db3b267e50a27da15de4c76813b Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Tue, 28 Feb 2012 14:35:49 +0800 Subject: [PATCH] MDL-31248 - lib - Alteration to the rc4encrypt function to allow for old password use. --- lib/moodlelib.php | 53 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index bde71c2787c..26b0f2f9f1b 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2747,7 +2747,7 @@ function set_moodle_cookie($thing) { $seconds = DAYSECS*$days; setCookie($cookiename, '', time() - HOURSECS, $CFG->sessioncookiepath, $CFG->sessioncookiedomain, $CFG->cookiesecure); - setCookie($cookiename, rc4encrypt($thing), time()+$seconds, $CFG->sessioncookiepath, $CFG->sessioncookiedomain, $CFG->cookiesecure); + setCookie($cookiename, rc4encrypt($thing, true), time()+$seconds, $CFG->sessioncookiepath, $CFG->sessioncookiedomain, $CFG->cookiesecure); } /** @@ -2764,8 +2764,23 @@ function get_moodle_cookie() { if (empty($_COOKIE[$cookiename])) { return ''; } else { - $thing = rc4decrypt($_COOKIE[$cookiename]); - return ($thing == 'guest') ? '': $thing; // Ignore guest account + $username = rc4decrypt($_COOKIE[$cookiename], true); + $username = moodle_strtolower($username); + $userdata = preg_replace('/[^-\.@_a-z0-9]/', '', $username); + if ($username != $userdata) { + $username = rc4decrypt($_COOKIE[$cookiename]); + $username = moodle_strtolower($username); + $userdata = preg_replace('/[^-\.@_a-z0-9]/', '', $username); + if ($userdata == $userdata) { + set_moodle_cookie($username); + } else { + $username = ''; + } + } + if ($username == 'guest') { // Ignore guest account + $username = ''; + } + return $username; } } @@ -6024,25 +6039,33 @@ function get_list_of_currencies() { /** * rc4encrypt * - * @param string $data ? - * @return string - * @todo Finish documenting this function + * @param string $data Data to encrypt. + * @param bool $usesecurekey Lets us know if we are using the old or new password. + * @return string The now encrypted data. */ -function rc4encrypt($data) { - $password = get_site_identifier(); - return endecrypt($password, $data, ''); +function rc4encrypt($data, $usesecurekey = false) { + if (!$usesecurekey) { + $passwordkey = 'nfgjeingjk'; + } else { + $passwordkey = get_site_identifier(); + } + return endecrypt($passwordkey, $data, ''); } /** * rc4decrypt * - * @param string $data ? - * @return string - * @todo Finish documenting this function + * @param string $data Data to decrypt. + * @param bool $usesecurekey Lets us know if we are using the old or new password. + * @return string The now decrypted data. */ -function rc4decrypt($data) { - $password = get_site_identifier(); - return endecrypt($password, $data, 'de'); +function rc4decrypt($data, $usesecurekey = false) { + if (!$usesecurekey) { + $passwordkey = 'nfgjeingjk'; + } else { + $passwordkey = get_site_identifier(); + } + return endecrypt($passwordkey, $data, 'de'); } /** -- 2.43.0