Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.15 KB | None | 0 0
  1. <?php
  2.    
  3.     function process_doLogin($username, $password, $remember) {
  4.         global $DBH;
  5.         if(!$username || trim($username) == "") {
  6.             messages_newError("You did not enter a username. A username must be entered.");
  7.         }
  8.         if(!eregi("^([0-9a-zA-Z])*$", $username)) {
  9.             messages_newError("Your username is invalid. Usernames must be alphanumeric.");
  10.         }
  11.         if(!$password || trim($password) == "") {
  12.             messages_newError("Your password is invalid. A password must be entered.");
  13.         }
  14.         if(messages_numErrors() == 0){
  15.             $password = md5($password);
  16.             $STH_userdetails = $DBH->prepare('SELECT * FROM users WHERE username = :username');
  17.             $STH_userdetails->execute(array(':username' => $username));
  18.             $STH_userdetailsres = $STH_userdetails->fetch(PDO::FETCH_OBJ);
  19.             if($STH_userdetails->rowCount() == 0){
  20.                 messages_newError("The username '".$username."' could not be found in the database.");
  21.             } else {
  22.                 if($password != $STH_userdetailsres->password){
  23.                     messages_newError("An incorrect password was entered for user '".$username."'.");
  24.                 } else {
  25.                     $_SESSION['userinfo'] = common_objectToArray($STH_userdetailsres);
  26.                     $_SESSION['username'] = $_SESSION['userinfo']['username'];
  27.                     messages_newSuccess("You've succesfully logged in. Enjoy your stay!");
  28.                 }
  29.             }
  30.         }
  31.     }
  32.    
  33.     function process_generatePassword(){
  34.         $chars = "abcdefghijkmnopqrstuvwxyz023456789";
  35.         srand((double)microtime()*1000000);
  36.         $i = 0;
  37.         $pass = '' ;
  38.         while ($i <= 7) {
  39.             $num = rand() % 33;
  40.             $tmp = substr($chars, $num, 1);
  41.             $pass = $pass . $tmp;
  42.             $i++;
  43.         }
  44.         return $pass;
  45.     }
  46.    
  47.     function process_doLogout(){
  48.         unset($_SESSION['userInfo']);
  49.         unset($_SESSION['username']);
  50.         messages_newSuccess("You've succesfully logged out. See you next time!");
  51.     }
  52.    
  53.     function process_updateOnlineUsers(){
  54.         global $DBH;
  55.         $username = $_SESSION['username'];
  56.         $ip = $_SERVER['REMOTE_ADDR'];
  57.         $key = md5(uniqid(rand(), true));
  58.         $timeout = time();
  59.         //echo time();
  60.         if($username){
  61.             $STH_useronline = $DBH->prepare('SELECT username FROM users_online WHERE username = :username');
  62.             $STH_useronline->execute(array(':username' => $username));
  63.             if($STH_useronline->rowCount() == 0){
  64.                 $STH_updateonline = $DBH->prepare('INSERT INTO users_online (username,lastactive,ip,key,timeout) VALUES (:username,time(),:ip,:key,:timeout)');
  65.                 $STH_updateonline->execute(array(':username' => '$username', ':ip' => '$ip', ':key' => '$key', ':timeout' => '$timeout'));
  66.             } else {
  67.                 mysql_query("UPDATE users_online SET timestamp = NOW() WHERE username = '$username'");
  68.             }
  69.         } else {
  70.             try {
  71.                 $STH_insertonlineguest = $DBH->prepare('INSERT INTO users_online (username,lastactive,ip) VALUES (:username,:lastactive,:ip)');
  72.             } catch(PDOException $e) {
  73.                 echo $e->getMessage(); 
  74.             }
  75.             $STH_insertonlineguest = $DBH->prepare('INSERT INTO users_online (username,lastactive,ip) VALUES (:username,:lastactive,:ip)');
  76.             //$STH_insertonlineguest->execute(array(':username' => 'guest',':lastactive' => '1293039944',':ip' => $ip));
  77.         }
  78.     }
  79.    
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement