Guest User

Untitled

a guest
Dec 29th, 2012
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. session_start();
  3.  
  4. //We connect to the database
  5. $host="localhost"; // Host name
  6. $username="root"; // Mysql username
  7. $password="testdbpass"; // Mysql password
  8. $db_name="test"; // Database name
  9.  
  10. // Connect to server via PHP Data Object
  11. $dbh = new PDO("mysql:host=localhost;dbname=test", $username, $password);
  12. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  13.  
  14. //How we creat our bcrypt
  15. $Blowfish_Pre = '$2y$17$';
  16. $Allowed_Chars =
  17. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./';
  18. $Chars_Len = 63;
  19. $salt = "";
  20. for($x=0;$x<10000;$x++)
  21. {
  22.     $salt .= $Allowed_Chars[mt_rand(0,$Chars_Len)];
  23. }
  24. $bcrypt = $Blowfish_Pre . $salt;
  25.  
  26. //The actual form data being combined with the database data
  27.  
  28. $form_username = $_POST['username'];
  29. $form_password = $_POST['password'];
  30. $crypt_pass = crypt($form_password, $bcrypt);
  31.  
  32.  
  33. $sth = $dbh->prepare("SELECT * FROM users WHERE username = :user AND password = :pass");
  34. $sth->bindParam(':user', $form_username);
  35. $sth->bindParam(':pass', $crypt_pass);
  36. $sth->execute();
  37. $total = $sth->rowCount();
  38. $row = $sth->fetch();
  39.  
  40. if($total > 0){
  41.     if($row['activated']){
  42.         $_SESSION["user_username"] = $form_username;
  43.         $_SESSION["user_logedIn"] = true;
  44.         $_SESSION["user_id"] = $row['user_id'];
  45.         header("location: login_success.php");  
  46.     }
  47.     else{
  48.         echo "ACCOUNT NOT ACTIVE";
  49.     }
  50. }
  51. else{
  52.     echo "WRONG PASSWORD OR USERNAME";
  53. }
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment