ClarkeRubber

Login Method

Jan 5th, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.93 KB | None | 0 0
  1. <?php
  2. $enc_user = md5(sha1($_SERVER['REMOTE_ADDR']));
  3.  
  4. function login_admin($enc_user){
  5.     /*basic method
  6.     If the user has a time stamp, check if the timestamps mathch, if they do, update the timestamp and login the user as admin.
  7.     If they don't match attempt to login the user using their IP address. If they are successful, issue them with a timestamp and update the local timestamp
  8.     as well as allowing them to login.
  9.     */
  10.     //check if the user has a timestamp
  11.     $admin = false; //assume that the user is not the admin.
  12.     if($_COOKIE['timestamp']){
  13.         $usr_timestamp = $_COOKIE['timestamp'];
  14.         if(file_exists("users/admin_timestamp.txt")){
  15.             $fh[1] = fopen("users/admin_timestamp.txt", 'r');
  16.             $admin_timestamp = trim(fgets($fh[1]));
  17.             fclose($fh[1]);
  18.             if(sha1(md5(crypt($usr_timestamp, $usr_timestamp))) == $admin_timestamp){
  19.                 //user is admin, log them in and update the timestamp file
  20.                 //updating the timestamp file is also an increased measure of security
  21.                 $fh[2] = fopen("users/admin_timestamp.txt", 'w');
  22.                 if(file_exists("users/admin_timestamp.txt")){
  23.                     $current_time = microtime()*rand(1, 100000000); //time in milliseconds*random value between 1 and 100 000 000 (one hundred million)
  24.                     //this will increase the amount of entropy involved in attempting to crack this system. (How does one crack random?)
  25.                     $usr_enc_timestamp = sha1(md5($current_time));
  26.                     $server_enc_timestamp = sha1(md5(crypt($usr_enc_timestamp, $usr_enc_timestamp)));
  27.                     //update the user and server timestamp files, as well as updating the admin.txt hash of the users IP
  28.                     setcookie("timestamp", $usr_enc_timestamp); //update user
  29.                     fwrite($fh[2], $server_enc_timestamp); //update server
  30.                     if(file_exists("users/admin.txt")){
  31.                         $fh[3] = fopen("users/admin.txt", 'w');
  32.                         fwrite($fh[3], $enc_user); //update the admin IP file
  33.                         fclose($fh[3]);
  34.                     }
  35.                     fclose($fh[2]);
  36.                 }
  37.                 $admin = true;
  38.             }
  39.         }
  40.     }
  41.     //Secondarily test if the IP addresses match if the login is still unsuccesful
  42.     if(!$admin){
  43.         //open the users file
  44.         $fh[4] = fopen("users/admin.txt", 'r');
  45.         $enc_admin = trim(fgets($fh[4]));
  46.         fclose($fh[4]);
  47.         if($enc_user == $enc_admin){
  48.             $fh[5] = fopen("users/admin_timestamp.txt", 'w');
  49.             if(file_exists("users/admin_timestamp.txt")){
  50.                 $current_time = microtime(); //time in milliseconds
  51.                 $usr_enc_timestamp = sha1(md5($current_time));
  52.                 $server_enc_timestamp = sha1(md5(crypt($usr_enc_timestamp, $usr_enc_timestamp)));
  53.                 //update the user and server timestamp files, as well as updating the admin.txt hash of the users IP
  54.                 setcookie("timestamp", $usr_enc_timestamp); //update user
  55.                 fwrite($fh[5], $server_enc_timestamp); //update server
  56.                 if(file_exists("users/admin.txt")){
  57.                     $fh[3] = fopen("users/admin.txt", 'w');
  58.                     fwrite($fh[3], $enc_user); //update the admin IP file
  59.                     fclose($fh[3]);
  60.                 }
  61.                 fclose($fh[5]);
  62.             }
  63.             $admin = true;
  64.         }
  65.     }
  66.     return $admin;
  67. }
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment