Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.51 KB | None | 0 0
  1. include('lib.php');
  2. $mysql = DBC::getDefault();
  3. $err = array();
  4.  
  5. foreach($_GET as $key => $value) {
  6.     $get[$key] = $lib->filter($value); //get variables are filtered.
  7. }
  8.  
  9. if ($_POST['DoLogin']=='Поехали!')
  10. {
  11.  
  12. foreach($_POST as $key => $value) {
  13.     $data[$key] = $lib->filter($value); // post variables are filtered
  14. }
  15.  
  16.  
  17. $username = $data['username'];
  18. $password = $data['password'];
  19.  
  20.    
  21. $result = $mysql->query("SELECT `id`,`password`,`favorite`,`user_level` FROM `stream_users` WHERE
  22.           `username`='".$username."' AND `banned` = '0'");
  23. $num = mysql_num_rows($result);
  24.  
  25.   // Match row found with more than 1 results  - the user is authenticated.
  26.     if ( $num > 0 ) {
  27.    
  28.     list($id,$password_sql,$favorite,$user_level) = mysql_fetch_row($result);
  29.    
  30.     //if(!$approved) {
  31.     //$msg = urlencode("Account not activated. Please check your email for activation code");
  32.     //$err[] = "Account not activated. Please check your email for activation code";
  33.    
  34.     //header("Location: login.php?msg=$msg");
  35.      //exit();
  36.     // }
  37.      
  38.         //check against salt
  39.     if ($password_sql === $lib->pass_hash($username,$password)){   
  40.     if(empty($err)){           
  41.  
  42.      // this sets session and logs user in  
  43.        session_start();
  44.        session_regenerate_id (true); //prevent against session fixation attacks.
  45.  
  46.        // this sets variables in the session
  47.         $_SESSION['user_id']= $id;  
  48.         $_SESSION['user_name'] = $username_sql;
  49.         $_SESSION['user_level'] = $user_level;
  50.         $_SESSION['HTTP_USER_AGENT'] = md5($_SERVER['HTTP_USER_AGENT']);
  51.         $_SESSION['favorite'] = $favorite;
  52.        
  53.         //update the timestamp and key for cookie
  54.         $stamp = time();
  55.         $ckey = $lib->GenKey();
  56.         $mysql->query("update stream_users set `ctime`='$stamp', `ckey` = '$ckey' where id='$id'");
  57.        
  58.         //set a cookie
  59.        
  60.        if(isset($_POST['remember'])){
  61.                   setcookie("user_id", $_SESSION['user_id'], time()+60*60*24*$cookie_timeout, "/");
  62.                   setcookie("user_key", sha1($ckey), time()+60*60*24*$cookie_timeout, "/");
  63.                   setcookie("user_name",$_SESSION['user_name'], time()+60*60*24*$cookie_timeout, "/");
  64.                   setcookie("favorite",$_SESSION['favorite'], time()+60*60*24*$cookie_timeout, "/");
  65.                    }
  66.           header("Location: index.php");
  67.          }
  68.         }
  69.         else
  70.         {
  71.         //$msg = urlencode("Invalid Login. Please try again with correct user email and password. ");
  72.         $err[] = "Invalid Login. Please try again with correct user email and password.";
  73.         //header("Location: login.php?msg=$msg");
  74.         }
  75.     } else {
  76.         $err[] = "Error - Invalid login. No such user exists";
  77.       }    
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement