Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.03 KB | None | 0 0
  1. <?php
  2.     require_once "connect.php";
  3.  
  4.     $link = @new mysqli($host,$db_user,$db_password,$db_name);
  5.    
  6.     $login = htmlentities($_POST['login'], ENT_QUOTES, "UTF-8");
  7.     $login = mysqli_real_escape_string($link, $login);
  8.     $passwd = htmlentities($_POST['haslo'], ENT_QUOTES, "UTF-8");
  9.     $passwd = mysqli_real_escape_string($link, $passwd);
  10.    
  11.     foreach ($_SERVER as $k=>$v) {$_SERVER[$k] = mysqli_real_escape_string($link, $v);}
  12.     if($link->connect_errno == 0){
  13.         if (isset($_POST['login'])){
  14.             $q = mysqli_query($link, "select salt from user where login = '$login' ") or die("Error: ". $link->error);
  15.             $salt = mysqli_fetch_array($q)['salt'];
  16.             $hashed_passwd = hash("sha256", $salt.$passwd);
  17.            
  18.             $q1 = mysqli_fetch_assoc( mysqli_query($link, "select count(*) cnt, id_user, id_user_type, user_name, user_surname, id_user_type from user where login='$login' and password ='$hashed_passwd'"));
  19.  
  20.             if ($q1['cnt']){
  21.                 $id = md5(rand(-10000,10000) . microtime()) . md5(crc32(microtime()) . $_SERVER['REMOTE_ADDR']);
  22.                 $token = rand(-1000,1000); 
  23.                 $userId =  $q1['id_user'];
  24.                 $userType =  $q1['id_user_type'];
  25.                 $userName =  mysqli_real_escape_string($link, $q1['user_name']);
  26.                 $userSurName = mysqli_real_escape_string($link, $q1['user_surname']);
  27.                 echo $userId. '</br>';
  28.                 echo $userType. '</br>';
  29.                 echo $userName. '</br>';
  30.                 echo $userSurName. '</br>';
  31.                 mysqli_query($link, "delete from session where ID_user = '$userId';");  
  32.                 $q2 = mysqli_query($link, "
  33.                     insert into session (ID_user, id_user_type, id, ip, web,imie,nazwisko,token,time) values
  34.                     ('$userId','$userType','$id','$_SERVER[REMOTE_ADDR]','$_SERVER[HTTP_USER_AGENT]','$userName','$userSurName','$token',CURRENT_TIMESTAMP)");
  35.                     if ($q2){
  36.                         setcookie("id", $id);
  37.                         setcookie("token", $token);
  38.                         header("location:index.php");
  39.                     } else {echo "błąd podczas logowania!";}
  40.                    
  41.                 } else {
  42.                     header("location: index.php");
  43.                     setcookie("login_error", true);
  44.                 }
  45.         }else{
  46.             header("location: index.php");
  47.         }
  48.     }
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement