Advertisement
Guest User

Untitled

a guest
Jul 19th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. <?php
  2. $password = $password2 = $key = $username = "";
  3. $keyErr = $usernameErr = $passwordErr = $password2Err = "";
  4.  
  5. if($_SERVER["REQUEST_METHOD"] == "POST"){
  6. $password = test_input($_POST["password"]);
  7. $password2 = test_input($_POST["password2"]);
  8. $username = test_input($_POST["username"]);
  9. $key = test_input($_POST["key"]);
  10.  
  11. //Key registration check
  12. if(strlen($key) < 4){
  13. $keyErr = "* Reg.key must be at least 4 characters!";
  14. } // check if key contains alphanumeric characters
  15. elseif(!preg_match("/^[a-zA-Z0-9]*$/",$key)) {
  16. $keyErr = "* Only alphanumeric characters allowed!";
  17. }
  18. else{
  19. $keyErr = "Continue";
  20. }
  21.  
  22. //Checks if username is shorter than 4 characters
  23. if(strlen($username) < 4){
  24. $usernameErr = "* Username must be at least 4 characters!";
  25. }
  26.  
  27. //Password check
  28. if(strlen($password) < 4){
  29. $passwordErr = "* Password must be 4 characters or longer!";
  30. }
  31.  
  32. //check if both password inputs are identical
  33. if($password != $password2)
  34. {
  35. $password2Err = "Password did not match! Try again. ";
  36. }
  37. else{
  38. $password2Err = "Hi, it works!";
  39. }
  40.  
  41. }
  42. function test_input($data) {
  43. $data = trim($data);
  44. $data = stripslashes($data);
  45. $data = htmlspecialchars($data);
  46. return $data;
  47. }
  48.  
  49. ?>
  50. <div class="container">
  51. <div id="registerContainer">
  52.  
  53. <h4>Register</h4>
  54. <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  55. <div class="form-control input-sm">Reg. Key: </div><input type="text" name="key" required>
  56. <span class="error"> <?php echo $keyErr;?></span>
  57. <div class="form-control input-sm">Username: </div><input type="text" name="username" required>
  58. <span class="error"> <?php echo $usernameErr;?></span>
  59. <div class="form-control input-sm">Password: </div><input type="password" name="password" required>
  60. <span class="error"> <?php echo $passwordErr;?></span>
  61. <div class="form-control input-sm">Re-type password: </div><input type="password" name="password2" required>
  62. <span class="error"> <?php echo $password2Err;?></span>
  63. <br><button type="submit" name="submit">Register</button>
  64.  
  65. </form>
  66.  
  67. </div>
  68. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement