Permalink
Browse files

MDL-31248 - lib - Alteration to the rc4encrypt function to allow for …

…old password use.
  • Loading branch information...
1 parent f24a1a7 commit 6704edc5bafb983b3fead8eb325965d9b10f34b2 @abgreeve abgreeve committed Feb 27, 2012
Showing with 31 additions and 13 deletions.
  1. +20 −10 lib/moodlelib.php
  2. +11 −3 lib/sessionlib.php
View
@@ -6849,25 +6849,35 @@ protected function prepare_emoticon_object($text, $imagename, $altidentifier = n
*
* @todo Finish documenting this function
*
- * @param string $data Data to encrypt
- * @return string The now encrypted data
+ * @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
*
* @todo Finish documenting this function
*
- * @param string $data Data to decrypt
- * @return string The now decrypted data
+ * @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');
}
/**
View
@@ -828,7 +828,7 @@ function set_moodle_cookie($username) {
if ($username !== '') {
// set username cookie for 60 days
- setcookie($cookiename, rc4encrypt($username), time()+(DAYSECS*60), $CFG->sessioncookiepath, $CFG->sessioncookiedomain, $CFG->cookiesecure, $CFG->cookiehttponly);
+ setcookie($cookiename, rc4encrypt($username, true), time()+(DAYSECS*60), $CFG->sessioncookiepath, $CFG->sessioncookiedomain, $CFG->cookiesecure, $CFG->cookiehttponly);
}
}
@@ -849,10 +849,18 @@ function get_moodle_cookie() {
if (empty($_COOKIE[$cookiename])) {
return '';
} else {
- $username = rc4decrypt($_COOKIE[$cookiename]);
+ $username = rc4decrypt($_COOKIE[$cookiename], true);
+ if ($username != clean_param($username, PARAM_USERNAME)) {
+ $username = rc4decrypt($_COOKIE[$cookiename]);
+ if ($username == clean_param($username, PARAM_USERNAME)) {
+ set_moodle_cookie($username);
+ } else {
+ $username = '';
+ }
+ }
if ($username === 'guest' or $username === 'nobody') {
// backwards compatibility - we do not set these cookies any more
- return '';
+ $username = '';
}
return $username;
}

0 comments on commit 6704edc

Please sign in to comment.