Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. $ini_array = parse_ini_file("./secret.ini", true);
  6. try{
  7.     $opts = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
  8.     $database = new PDO($ini_array['section']['dsn'], $ini_array['section']['user'], $ini_array['section']['password'], $opts);
  9. } catch (Exception $e) {
  10.         exit('Erreur de connexion à la base de donnée.'.$e->getMessage());
  11. }
  12.  
  13. $data = $database->prepare('Select password,id,rank From Users Where login = ?');
  14. $data->execute(array($_POST['username']));
  15. $result = $data->fetch();
  16. $isPasswordCorrect = password_verify($_POST['password'], $result['password']);
  17.  
  18. if($isPasswordCorrect) {
  19.     $_SESSION['user'] = $_POST['username'];
  20.     $_SESSION['id'] = $result['id'];
  21.     $_SESSION['rank_user'] = $result['rank'];
  22.     header('Location: /calendar/calendar.php');
  23.     exit();
  24. }
  25. else {
  26.     $error = 1;
  27.     include('./sign in.php');
  28.     exit();
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement