Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. <?php
  2. // Include database connection and functions here.
  3. include 'db_connect.php';
  4. include 'functions.php';
  5.  
  6. // The hashed password from the form
  7. $password = $_POST['p'];
  8. // Create a random salt
  9. $random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
  10. // Create salted password (Careful with the chilli)
  11. $password = hash('sha512', $password.$random_salt);
  12. $username = $mysqli->real_escape_string($_POST['username']);
  13. $email = $mysqli->real_escape_string($_POST['email']);
  14. $stmt = $mysqli->prepare("SELECT * FROM members WHERE username = ? LIMIT 1");
  15. $stmt->bind_param('s', $username);
  16. $stmt->execute(); // Execute the prepared query.
  17. $stmt->store_result();
  18. if($stmt->num_rows == 1) {
  19. header("Location: '......?registrationfailed=1'");
  20. }
  21. else
  22. {
  23. if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email, password, salt) VALUES (?, ?, ?, ?)"))
  24. {
  25. $insert_stmt->bind_param('ssss', $username, $email, $password, $random_salt);
  26. // Execute the prepared query.
  27. $insert_stmt->execute();
  28. header("Location: '......?success=1'");
  29.  
  30. }
  31. else
  32. {
  33. header("Location: '......?registrationfailed=1'");
  34. }
  35. }
  36.  
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement