Browse Source

New session cookie code - Remove CRYPT class

spaghetti 8 years ago
parent
commit
214f489bd7
3 changed files with 7 additions and 53 deletions
  1. 0
    34
      classes/encrypt.class.php
  2. 3
    9
      classes/script_start.php
  3. 4
    10
      sections/login/index.php

+ 0
- 34
classes/encrypt.class.php View File

@@ -1,34 +0,0 @@
1
-<?
2
-/*************************************************************************|
3
-|--------------- Encryption class ----------------------------------------|
4
-|*************************************************************************|
5
-
6
-This class handles encryption and decryption, that's all folks.
7
-
8
-|*************************************************************************/
9
-
10
-if (!extension_loaded('mcrypt')) {
11
-  die('Mcrypt Extension not loaded.');
12
-}
13
-
14
-class CRYPT {
15
-  public function encrypt($Str, $Key = ENCKEY) {
16
-    srand();
17
-    $Str = str_pad($Str, 32 - strlen($Str));
18
-    $IVSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
19
-    $IV = mcrypt_create_iv($IVSize, MCRYPT_RAND);
20
-    $CryptStr = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $Key, $Str, MCRYPT_MODE_CBC, $IV);
21
-    return base64_encode($IV.$CryptStr);
22
-  }
23
-
24
-  public function decrypt($CryptStr, $Key = ENCKEY) {
25
-    if ($CryptStr != '') {
26
-      $IV = substr(base64_decode($CryptStr), 0, 16);
27
-      $CryptStr = substr(base64_decode($CryptStr), 16);
28
-      return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $Key, $CryptStr, MCRYPT_MODE_CBC, $IV));
29
-    } else {
30
-      return '';
31
-    }
32
-  }
33
-} // class ENCRYPT()
34
-?>

+ 3
- 9
classes/script_start.php View File

@@ -51,7 +51,6 @@ ob_start(); //Start a buffer, mainly in case there is a mysql error
51 51
 require(SERVER_ROOT.'/classes/debug.class.php'); //Require the debug class
52 52
 require(SERVER_ROOT.'/classes/mysql.class.php'); //Require the database wrapper
53 53
 require(SERVER_ROOT.'/classes/cache.class.php'); //Require the caching class
54
-require(SERVER_ROOT.'/classes/encrypt.class.php'); //Require the encryption class
55 54
 require(SERVER_ROOT.'/classes/time.class.php'); //Require the time class
56 55
 require(SERVER_ROOT.'/classes/paranoia.class.php'); //Require the paranoia check_paranoia function
57 56
 require(SERVER_ROOT.'/classes/regex.php');
@@ -63,7 +62,6 @@ $Debug->set_flag('Debug constructed');
63 62
 
64 63
 $DB = new DB_MYSQL;
65 64
 $Cache = new CACHE(MEMCACHED_SERVERS);
66
-$Enc = new CRYPT;
67 65
 
68 66
 // Autoload classes.
69 67
 require(SERVER_ROOT.'/classes/classloader.php');
@@ -93,12 +91,9 @@ list($Classes, $ClassLevels) = Users::get_classes();
93 91
 // Enabled - if the user's enabled or not
94 92
 // Permissions
95 93
 
96
-if (isset($_COOKIE['session'])) {
97
-  $LoginCookie = $Enc->decrypt($_COOKIE['session']);
98
-}
99
-if (isset($LoginCookie)) {
100
-  list($SessionID, $LoggedUser['ID']) = explode('|~|', $Enc->decrypt($LoginCookie));
101
-  $LoggedUser['ID'] = (int)$LoggedUser['ID'];
94
+if (isset($_COOKIE['session']) && isset($_COOKIE['userid'])) {
95
+  $SessionID = $_COOKIE['session'];
96
+  $LoggedUser['ID'] = (int)$_COOKIE['userid'];
102 97
 
103 98
   $UserID = $LoggedUser['ID']; //TODO: UserID should not be LoggedUser
104 99
 
@@ -138,7 +133,6 @@ if (isset($LoginCookie)) {
138 133
     $Cache->cache_value('enabled_'.$LoggedUser['ID'], $Enabled, 0);
139 134
   }
140 135
   if ($Enabled == 2) {
141
-
142 136
     logout();
143 137
   }
144 138
 

+ 4
- 10
sections/login/index.php View File

@@ -235,16 +235,10 @@ else {
235 235
               WHERE Username = '".db_string($_POST['username'])."'");
236 236
           }
237 237
           if ($Enabled == 1) {
238
-            $SessionID = Users::make_secret();
239
-            $Cookie = $Enc->encrypt($Enc->encrypt($SessionID.'|~|'.$UserID));
240
-
241
-            if (isset($_POST['keeplogged']) && $_POST['keeplogged']) {
242
-              $KeepLogged = 1;
243
-              setcookie('session', $Cookie, time() + 60 * 60 * 24 * 365, '/', '', true, true);
244
-            } else {
245
-              $KeepLogged = 0;
246
-              setcookie('session', $Cookie, 0, '/', '', true, true);
247
-            }
238
+            $SessionID = Users::make_secret(64);
239
+            $KeepLogged = ($_POST['keeplogged'] ?? false) ? 1 : 0;
240
+            setcookie('session', $SessionID, (time()+60*60*24*365)*$KeepLogged, '/', '', true, true);
241
+            setcookie('userid', $UserID, (time()+60*60*24*365)*$KeepLogged, '/', '', true, true);
248 242
 
249 243
             // Because we <3 our staff
250 244
             $Permissions = Permissions::get_permissions($PermissionID);

Loading…
Cancel
Save