Guest User

Untitled

a guest
Sep 30th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. <?php
  2. $name = $_POST['username'];
  3. $password = $_POST['password'];
  4. $email = $_POST['email'];
  5. $hash = md5 (rand(0,1000));
  6. if(isset($name))
  7. {
  8. if (trim($name) == '' || trim($name) == ' ')
  9. {
  10. print_r('Username cannot be empty');
  11. }
  12. else
  13. {
  14. if(preg_match('/^[a-zA-Z0-9]{5,}$/', $name))
  15. { // for english chars + numbers only
  16. if( strlen($password) < 8 ) { print_r("Password too short!"); }
  17. elseif( !preg_match("#[0-9]+#", $password) ) { print_r("Password must include at least one number!"); }
  18. elseif( !preg_match("#[a-z]+#", $password) ) { print_r("Password must include at least one letter!"); }
  19. elseif( !preg_match("#[A-Z]+#", $password) ) { print_r("Password must include at least one CAPS!"); }
  20. elseif( !preg_match("#W+#", $password) ) { print_r("Password must include at least one symbol!"); }
  21. else
  22. {
  23. if(isset($_POST['submit']))
  24. {
  25. if(filter_var($email, FILTER_VALIDATE_EMAIL))
  26. {
  27. $subject = 'Signup | Verification'; // Give the email a subject
  28. $message = '
  29.  
  30. Thanks for signing up!
  31. Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below.
  32.  
  33. ------------------------
  34. Username: '.$name.'
  35. Password: '.$password.'
  36. ------------------------
  37.  
  38. Please click this link to activate your account:
  39. http://www.mywebsite.com/verify.php?email='.$email.'&hash='.$hash.'
  40.  
  41. '; // Our message above including the link
  42.  
  43. $headers = 'From:asdf@mywebsite.com' . "rn"; // Set from headers
  44.  
  45. if(!isset($con))
  46. {
  47. $config = parse_ini_file('config2.ini');
  48. $con = mysqli_connect(`localhost`,$config["username"],$config["password"],$config["dbname"])or die ("MySQL Error: " . mysqli_connect_error());
  49. }
  50. $stmt = $con->prepare("SELECT login FROM Accounts WHERE login=?");
  51. $stmt->bind_param("s", $GLOBALS['name']);
  52. $stmt->execute();
  53. $stmt->bind_result($un);
  54. $usernamefound = 'false';
  55. while ($stmt->fetch())
  56. {
  57. if(isset($un))
  58. {
  59. $usernamefound = 'true';
  60. print_r ('Username already exists.');
  61. }
  62. }
  63. $stmt->close();
  64.  
  65. if ($usernamefound == 'false')
  66. {
  67. if (filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP) || filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
  68. {
  69. $ip = filter_var($_SERVER['REMOTE_ADDR']);
  70. mail($email, $subject, $message, $headers); // Send our email
  71. $hashed_password = password_hash($GLOBALS['password'], PASSWORD_DEFAULT);
  72. $result = $con->prepare('INSERT INTO Accounts(login,password,email,lastip,hash) VALUES (?, ?, ?, ?, ?)');
  73. $result->bind_param("sssss", $GLOBALS['name'], $hashed_password, $GLOBALS['email'], $ip, $GLOBALS['hash']);
  74. $result->execute();
  75. $result->close();
  76. $con->close();
  77. echo "Registered: " . $ip;
  78. }
  79. else
  80. {
  81. header('Location: noIPError.html');
  82. die();
  83. }
  84. echo "<br/>";
  85. // Return Success - Valid Email
  86. print_r('Your account has been made, <br /> please verify it by clicking the activation link that has been send to your email.');
  87. }
  88. }
  89. else
  90. {
  91. // Return Error - Invalid Email
  92. print_r('The email you have entered is invalid, please try again.');
  93. }
  94. }
  95. }
  96. }
  97. else
  98. {
  99. print_r('Invalid Username: Must be alphanumeric and longer than or equal to 5 chars');
  100. echo "<br/>";
  101. print_r('No special characters or spaces allowed');
  102. }
  103. }
  104. }
  105. ?>
Add Comment
Please, Sign In to add comment