overvolt

login.php

Feb 17th, 2018
874
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. <?php
  2.   include_once('funzioni.php');
  3.   if (isset($_POST['send'])) {
  4.     if (empty($_POST['email']) || empty($_POST['password'])) {
  5.       echo "Inserire email e password!";
  6.     }
  7.     else{
  8.       $db = database_connect() or die("Errore di connessione");
  9.       $email=$db->escape_string($_POST['email']);
  10.       $password=hash("sha512", $db->escape_string($_POST['password']));
  11.       $time = time();
  12.       $result = $db->query("SELECT * from utenti where password='$password' AND email='$email' AND confermato='1'") or  die('ERRORE: ' . $db->error);
  13.       if($result->num_rows == 1) {
  14.          $row=$result->fetch_assoc();
  15.          $hash = bin2hex(openssl_random_pseudo_bytes(32));
  16.          $db->query("DELETE from sessioni where userid = '".$row['id']."'") or die('ERRORE: ' . $db->error);
  17.          $db->query("INSERT INTO sessioni (user, userid, time) VALUES ('".$row['id']."', '$hash', $time)") or die('ERRORE: ' . $db->error);
  18.          session_start();
  19.          $_SESSION['login_user']=$hash;
  20.          header("Location: ../home.php");
  21.       }
  22.       else{
  23.         session_start();
  24.         $_SESSION['login_user']=-1;
  25.         echo 'Username o password non validi';
  26.       }
  27.     }
  28.   }
  29.  
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment