nstruth2

Need Help With Code Please

Jul 11th, 2023
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.24 KB | Source Code | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>Register Page</title>
  5. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  6. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  7. <link rel="stylesheet" type="text/css" href="mystyle.css">
  8. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  9. <body>
  10. <form method="post" action="" name="signup-form">
  11. <div class="form-element">
  12. <label style="color: white">Username</label>
  13. <input type="text" name="username" pattern="[a-zA-Z0-9]+" required />
  14. </div>
  15. <div class="form-element">
  16. <label style="color: white; padding-right: 2px">Email&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
  17. <input type="email" name="email" required />
  18. </div>
  19. <div class="form-element">
  20. <label style="color: white; padding-right: 3px">Password</label>
  21. <input type="password" name="password" required />
  22. </div>
  23. <button type="submit" name="register" value="register">Register</button>
  24. </form>
  25. <a href="login2.php" class="btn btn-info btn-lg">
  26. <span class="glyphicon glyphicon-log-in"></span> Log in
  27. </a>
  28. <a href="index2.php">Main Page</a>
  29. <?php
  30. session_start();
  31. include('config.php');
  32. if (isset($_POST['register'])) {
  33. $username = $_POST['username'];
  34. $email = $_POST['email'];
  35. $password = $_POST['password'];
  36. $err = "";
  37.              
  38.                 if (strlen($password) < 8) {
  39.                    
  40.                     $err .= "Password must be at least 8 characters long!<br>";
  41.  
  42.                 }
  43.  
  44.                 if (strlen($password) > 34) {
  45.                    
  46.                     $err .= "Password can be 34 characters maximum!<br>";
  47.  
  48.                 }
  49.  
  50.                 if (!preg_match("/[0-9][A-Z]/", $password)) {
  51.                    
  52.                     $err .= "Password must contain a number and at least one uppercase letter in it!<br>";
  53.  
  54.                 }
  55.  
  56.                     if (!preg_match("/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*_)(?=.*[^a-zA-Z0-9]).{8,16}$/", $password)) {
  57.                        
  58.                         $err .= "Password not strong enough!";
  59.  
  60.                     }
  61.  
  62.                
  63.                 if (!$err == "") {
  64.            
  65.             echo
  66.             '<div class="col-md-12">
  67.            <br>
  68.            <div class="alert alert-danger" role="alert">
  69.            '.$err.'
  70.            </div>
  71.            </div>';
  72.  
  73.         }else{
  74. $password_hash = password_hash($password, PASSWORD_BCRYPT);
  75. $query = $connection->prepare("SELECT * FROM users WHERE email=:email");
  76. $query->bindParam("email", $email, PDO::PARAM_STR);
  77. $query->execute();
  78. if ($query->rowCount() > 0) {
  79. echo '<p class="error">The email address is already registered!</p>';
  80. }
  81. if ($query->rowCount() == 0) {
  82. $query = $connection->prepare("INSERT INTO users(username,password,email) VALUES (:username,:password_hash,:email)");
  83. $query->bindParam("username", $username, PDO::PARAM_STR);
  84. $query->bindParam("password_hash", $password_hash, PDO::PARAM_STR);
  85. $query->bindParam("email", $email, PDO::PARAM_STR);
  86. $result = $query->execute();
  87. if ($result) {
  88. echo '<p class="success">Your registration was successful!</p>';
  89. } else {
  90. echo '<p class="error">Something went wrong!</p>';
  91. }
  92. }
  93. }
  94. }
  95. ?>
  96. </body>
  97. </html>
Advertisement
Add Comment
Please, Sign In to add comment