Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $enc_user = md5(sha1($_SERVER['REMOTE_ADDR']));
- function login_admin($enc_user){
- /*basic method
- If the user has a time stamp, check if the timestamps mathch, if they do, update the timestamp and login the user as admin.
- 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
- as well as allowing them to login.
- */
- //check if the user has a timestamp
- $admin = false; //assume that the user is not the admin.
- if($_COOKIE['timestamp']){
- $usr_timestamp = $_COOKIE['timestamp'];
- if(file_exists("users/admin_timestamp.txt")){
- $fh[1] = fopen("users/admin_timestamp.txt", 'r');
- $admin_timestamp = trim(fgets($fh[1]));
- fclose($fh[1]);
- if(sha1(md5(crypt($usr_timestamp, $usr_timestamp))) == $admin_timestamp){
- //user is admin, log them in and update the timestamp file
- //updating the timestamp file is also an increased measure of security
- $fh[2] = fopen("users/admin_timestamp.txt", 'w');
- if(file_exists("users/admin_timestamp.txt")){
- $current_time = microtime()*rand(1, 100000000); //time in milliseconds*random value between 1 and 100 000 000 (one hundred million)
- //this will increase the amount of entropy involved in attempting to crack this system. (How does one crack random?)
- $usr_enc_timestamp = sha1(md5($current_time));
- $server_enc_timestamp = sha1(md5(crypt($usr_enc_timestamp, $usr_enc_timestamp)));
- //update the user and server timestamp files, as well as updating the admin.txt hash of the users IP
- setcookie("timestamp", $usr_enc_timestamp); //update user
- fwrite($fh[2], $server_enc_timestamp); //update server
- if(file_exists("users/admin.txt")){
- $fh[3] = fopen("users/admin.txt", 'w');
- fwrite($fh[3], $enc_user); //update the admin IP file
- fclose($fh[3]);
- }
- fclose($fh[2]);
- }
- $admin = true;
- }
- }
- }
- //Secondarily test if the IP addresses match if the login is still unsuccesful
- if(!$admin){
- //open the users file
- $fh[4] = fopen("users/admin.txt", 'r');
- $enc_admin = trim(fgets($fh[4]));
- fclose($fh[4]);
- if($enc_user == $enc_admin){
- $fh[5] = fopen("users/admin_timestamp.txt", 'w');
- if(file_exists("users/admin_timestamp.txt")){
- $current_time = microtime(); //time in milliseconds
- $usr_enc_timestamp = sha1(md5($current_time));
- $server_enc_timestamp = sha1(md5(crypt($usr_enc_timestamp, $usr_enc_timestamp)));
- //update the user and server timestamp files, as well as updating the admin.txt hash of the users IP
- setcookie("timestamp", $usr_enc_timestamp); //update user
- fwrite($fh[5], $server_enc_timestamp); //update server
- if(file_exists("users/admin.txt")){
- $fh[3] = fopen("users/admin.txt", 'w');
- fwrite($fh[3], $enc_user); //update the admin IP file
- fclose($fh[3]);
- }
- fclose($fh[5]);
- }
- $admin = true;
- }
- }
- return $admin;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment