Advertisement
Guest User

rev2

a guest
May 7th, 2014
2,165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. try {
  4.     $dbh = new PDO("mysql:host=localhost;dbname=database_name_here", "database_user_name_here", "database_users_password_here");
  5.     $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  6. } catch (PDOException $e) {
  7.     header("location: http://yourexternalsupportforum.io");
  8.     die('Failed to connect to database');
  9. }
  10.  
  11.  
  12. function NewUser()
  13. {
  14.     global $dbh;
  15.     $fullname = trim($_POST['name']); //at a minimus clear whitespace.
  16.     $userName = trim($_POST['user']);
  17.     $email = trim($_POST['email']);
  18.     $password =  trim($_POST['pass']);
  19.     $options = [
  20.         'cost' => 12, //higher = more lower= less. you want it to take around 0.4 seconds for security reasons!
  21.     ];
  22.     $password = password_hash($password, PASSWORD_BCRYPT, $options); // hashed password for storage!
  23.     $stmt = $dbh->"INSERT INTO websiteusers (fullname,userName,email,pass) VALUES (?,?,?,?)";
  24.     $stmt->bindValue(1,$fullname,PDO::PARAM_STR);
  25.     $stmt->bindValue(2,$userName,PDO::PARAM_STR);
  26.     $stmt->bindValue(3,$email,PDO::PARAM_STR);
  27.     $stmt->bindValue(4,$password,PDO::PARAM_STR);
  28.     if($stmt->execute())
  29.     {
  30.     echo "YOUR REGISTRATION IS COMPLETED...";
  31.     }
  32. }
  33.  
  34. function SignUp()
  35. {
  36. global $dbh;
  37. if(!empty($_POST['user']))   //checking the 'user' name which is from Sign-Up.html, is it empty or have some text
  38. {
  39.     $user = trim($_POST['user']);
  40.     $pass = trim($_POST['pass']);
  41.     $stmt = $dbh->prepare("SELECT * FROM websiteusers WHERE userName = ?") ;
  42.     $stmt->bindValue(1,$_POST['user'],PDO::PARAM_STR);
  43.     $stmt->execute();
  44.     $selected_row = $stmt->fetch(PDO::FETCH_ASSOC);
  45.     if(!password_verify($pass, $selected_row['pass'])) // check password agaisnt stored hash
  46.     {
  47.         newuser();
  48.     }
  49.     else
  50.     {
  51.         echo "SORRY...YOU ARE ALREADY REGISTERED USER...";
  52.     }
  53. }
  54. }
  55. if(isset($_POST['submit']))
  56. {
  57.     SignUp();
  58. }
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement