Advertisement
Guest User

Untitled

a guest
Sep 9th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. <div class="errors-container">
  2. <?php
  3. if (isset($_POST['registerBtn']))
  4. {
  5. $username = $_POST['username'];
  6. $password = $_POST['passwd'];
  7. $repeat = $_POST['rpasswd'];
  8. $email = $_POST['email'];
  9. $terms = $_POST['terms'];
  10. $errors = array();
  11. if (empty($username) || empty($password) || empty($repeat) || empty($email))
  12. {
  13. $errors[] = 'Please fill in all required fields.';
  14. }
  15. $checkUsername = $odb -> prepare("SELECT * FROM `users` WHERE `username`= :username");
  16. $checkUsername -> execute(array(':username' => $username));
  17. $countUsername = $checkUsername -> rowCount();
  18. if ($countUsername != 0)
  19. {
  20. $errors[] = 'The username you have entered is already in use.';
  21. }
  22. $checkEmail = $odb -> prepare("SELECT * FROM `users` WHERE `email`= :email");
  23. $checkEmail -> execute(array(':email' => $email));
  24. $countEmail = $checkEmail -> rowCount();
  25. if ($countEmail0 != 0)
  26. {
  27. $errors[] = 'The email you have entered is already in use.';
  28. }
  29. if (strlen($_POST['passwd']) < 4) {
  30. $errors[] = 'The username you have entered is too short.';
  31. }
  32. if (strlen($_POST['username']) > 15) {
  33. $errors[] = 'The username you have entered is too long.';
  34. }
  35. if (!filter_var($email, FILTER_VALIDATE_EMAIL))
  36. {
  37. $errors[] = 'You have entered an invalid e-mail address.';
  38. }
  39. if (!ctype_alnum($username))
  40. {
  41. $errors[] = 'The username you have entered is invalid.';
  42. }
  43. if ($password != $repeat)
  44. {
  45. $errors[] = 'The passwords you have entered does not match.';
  46. }
  47. if ($terms != 'agree')
  48. {
  49. $errors[] = 'You have to agree t.o.s before using our service.';
  50. }
  51. if (empty($errors))
  52. {
  53. $sha = hash("sha512", $password);
  54. $activation = generateRandomString();
  55. $insertUser = $odb -> prepare("INSERT INTO `users` VALUES(NULL, :username, :password, :email, 0, 0, 0, 0, 0)");
  56. $insertUser -> execute(array(':username' => $username, ':password' => $sha, ':email' => $email));
  57. //Send mail here
  58.  
  59. echo '<div class="alert alert-success fade in"><button type="button" class="close close-sm" data-dismiss="alert"><i class="fa fa-times"></i></button><strong>Success!</strong> You have registered your account successfully! Redirecting..</div><meta http-equiv="refresh" content="3;url=login.php">';
  60. }
  61. else
  62. {
  63. echo '<div class="alert alert-block alert-danger fade in"><button type="button" class="close close-sm" data-dismiss="alert"><i class="fa fa-times"></i></button><strong>Oops!</strong><br />';
  64. foreach($errors as $error)
  65. {
  66. echo '- '.$error.'<br />';
  67. }
  68. echo '</div>';
  69. }
  70. }
  71. ?>
  72. </div>
  73.  
  74. <form method="post" role="form" id="register">
  75. <div class="form-group">
  76. <label for="Username">Username</label>
  77. <input type="text" class="form-control" required name="username" id="username" placeholder="Username" autocomplete="off" autofocus/>
  78. </div>
  79. <div class="form-group">
  80. <label for="c-email">Email</label>
  81. <input type="email" class="form-control" required name="email" id="email" placeholder="E-Mail Address" autocomplete="off" />
  82. </div>
  83. <div class="form-group">
  84. <label for="pwd">Password:</label>
  85. <input type="password" class="form-control" required name="passwd" id="passwd" placeholder="Password" autocomplete="off" />
  86. </div>
  87. <div class="form-group">
  88. <label for="c-pwd">Confirm Password:</label>
  89. <input type="password" class="form-control" required id="rpasswd" name="rpasswd" placeholder="Confirm Password" autocomplete="off" />
  90. </div>
  91.  
  92.  
  93.  
  94. <div class="checkbox">
  95. <label><input type="checkbox" name="terms" value="agree"> I agree to the <a>terms & conditions</a></label>
  96. </div>
  97. <input class="login-btn btn-block" type="submit" name="registerBtn" value="Sign Up"><i class="fa-plus"></i>
  98. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement