Advertisement
Guest User

PHP user registration script

a guest
Dec 29th, 2012
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. <?php
  2. //We connect to the database
  3. $host="localhost"; // Host name
  4. $username="root"; // Mysql username
  5. $password="testdbpass"; // Mysql password
  6. $db_name="test"; // Database name
  7.  
  8. // Connect to server via PHP Data Object
  9. $dbh = new PDO("mysql:host=localhost;dbname=test", $username, $password);
  10. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11.  
  12. //Validation
  13.  
  14.  
  15. CRYPT_BLOWFISH or die ('No Blowfish found.');
  16.  
  17. //This string tells crypt to use blowfish for 15 rounds.
  18. $Blowfish_Pre = '$2y$17$';
  19.  
  20. // Blowfish accepts these characters for salts.
  21. $Allowed_Chars =
  22. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./';
  23. $Chars_Len = 63;
  24.  
  25.  
  26.  
  27. $salt = "";
  28.  
  29. for($i=0;$i<45 ;$i++)
  30. {
  31.     $salt .= $Allowed_Chars[mt_rand(0,$Chars_Len)];
  32. }
  33. $bcrypt = $Blowfish_Pre . $salt;
  34.  
  35. $password = crypt($_POST['password'] , $bcrypt) ;
  36.  
  37. // Insert statements with PDO
  38.  
  39. try {
  40.         $query = $dbh->prepare("INSERT INTO `users` (username, email, fname, lname, password)
  41.                                VALUES (:username, :email, :first, :last, :password)");
  42.        
  43.         $query->execute(
  44.                         array(
  45.                         'username'  => $_POST['username'],
  46.                         'email'     => $_POST['email'],
  47.                         'first'     => $_POST['fname'],
  48.                         'last'      => $_POST['lname'],
  49.                         'password'  => $password
  50.                         ));
  51.     }
  52.    
  53.     catch (PDOException $e) {
  54.         error_log($e->getMessage());
  55.         die($e->getMessage());
  56.     }
  57.    
  58.     $dbh= null;
  59.    
  60.     ?>
  61.  
  62. <html>
  63.     <body>
  64.         <p>
  65.             Thank you for registering your account. Please wait for administrator approval before doing anything else. Thank you - System Administrator.
  66.         </p>
  67.     </body>
  68. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement