Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['register'])) {
  3. $username = htmlentities($_POST['username'], ENT_QUOTES);
  4. $usernamel = strtolower($username);
  5. $password = htmlentities($_POST['password'], ENT_QUOTES);
  6. $password_hash = password_hash($password, PASSWORD_BCRYPT);
  7. $email = htmlentities($_POST['email'], ENT_QUOTES);
  8. $ip = $_SERVER['REMOTE_ADDR'];
  9. $time = date("Y-m-d");
  10.  
  11. if($username == ""){
  12. echo "Username is empty";
  13. exit;
  14. }
  15.  
  16. if($password == ""){
  17. echo "Password is empty";
  18. exit;
  19. }
  20.  
  21. if($email == ""){
  22. echo "Email is empty";
  23. exit;
  24. }
  25.  
  26. if (strlen($username) < 10 && preg_match('/[^a-z0-9]+/i', $username) < 1) {
  27. if (strlen($password) > 8) {
  28. $mysqli_query = sprintf("SELECT username FROM users WHERE username = '$username'", mysqli_real_escape_string($db_mysqli, $username));
  29. $conn = $db_mysqli->query($mysqli_query);
  30.  
  31. if ($conn->num_rows <= 0) {
  32. $conn->close();
  33. $mysqli_query = sprintf("SELECT email FROM users WHERE email = '$email'", mysqli_real_escape_string($db_mysqli, $email));
  34. $conn = $db_mysqli->query($mysqli_query);
  35.  
  36. if ($conn->num_rows <= 0) {
  37. $conn->close();
  38. $stmt = $db_mysqli->prepare("INSERT INTO users (username, password, email, date, ip) VALUES (?, ?, ?, ?, ?)");
  39. $stmt->bind_param("sssss", $username1, $password_hashed, $email, $time, $ip);
  40. $stmt->execute();
  41. $stmt->close();
  42.  
  43. echo "<center>Registered, redirecting in 3 seconds.</center>";
  44. echo "<meta http-equiv='refresh' content='3;url=index.php'>";
  45. }
  46.  
  47.  
  48. } else {
  49. $stmt->close();
  50. echo "Email is already in use.";
  51. exit;
  52. }
  53. } else {
  54. $stmt->close();
  55. echo "Username is already in use.";
  56. exit;
  57. }
  58. }
  59. else {
  60. $stmt->close();
  61. echo "Password isnt enough strong, minimum is 8.";
  62. exit;
  63. }
  64. }
  65. else {
  66. $stmt->close();
  67. echo "Username needs to be less than 10 and cant contains special characters.";
  68. exit;
  69. }
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement