Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LOGIN.PHP
- <h1>Login</h1>
- <form method="POST">
- <input style="width: 200px;" type="text" name="username"><br />
- <input style="width: 200px;" type="password" name="password"><br />
- <input style="width: 200px; margin-top: 10px;" type="submit"><br />
- <a href="register.php">Register</a>
- </form>
- <?php
- error_reporting(0);
- session_start();
- if(isset($_POST['username'], $_POST['password'])) {
- require 'core/connect.php';
- $query = dbConnect()->prepare("SELECT username, password FROM users WHERE username=:username AND password=:password");
- $query->bindParam(':username', $_POST['username']);
- $query->bindParam(':password', ($_POST['password']));
- $query->execute();
- if($row = $query->fetch()) {
- $_SESSION['username'] = $row['username'];
- $_SESSION['password'] = $row['password'];
- header("Location: index.php");
- } else {
- echo '<p style="color: red;">Invalid username/password</p>';
- }
- }
- ?>
- // REGISTER.PHP
- <h1>Register</h1>
- <form method="POST">
- <input style="margin-bottom: 5px;" type="text" name="username" placeholder="Username" required><br />
- <input style="margin-bottom: 5px;" type="password" name="password" placeholder="Password" required><br />
- <input style="margin-bottom: 5px;" type="password" name="cpassword" placeholder="Confirm Password" required><br />
- <input style="margin-bottom: 10px;" type="email" name="email" placeholder="Email Address" required><br />
- <input style="width: 175px;" type="submit">
- </form>
- <?php
- session_start();
- if(isset($_POST['username'], $_POST['password'], $_POST['cpassword'], $_POST['email'])){
- require 'core/connect.php';
- error_reporting(0);
- $username = $_POST['username'];
- $password = $_POST['password'];
- $cpassword = $_POST['cpassword'];
- $email = $_POST['email'];
- $query = dbConnect()->prepare("INSERT INTO users (username, password, cpassword, email) VALUES (:username, :password, :cpassword, :email)");
- $query->bindParam(':username', $_POST['username']);
- $query->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
- $query->bindParam(':cpassword', password_hash($_POST['cpassword'], PASSWORD_BCRYPT));
- $query->bindParam(':email', $_POST['email']);
- // Check to make sure username is no less then 6 characters,
- // and is no more then 25 characters.
- if(strlen($username)<6 || strlen($username)>25) {
- echo '<p style="color: red;">Username must be between 6 and 25 characters</p>';
- } elseif($password != $cpassword) {
- // If password fields don't match - show the following error
- echo '<p style="color: red;">Passwords do not match</p>';
- } elseif(strlen($password)<8 || strlen($cpassword)<8) {
- // If password field is less then 8 characters show this error:
- echo '<p style="color: red;">Password must be at least 8 characters</p>';
- } else {
- // If no errors are found, write credentials to database
- $query->execute();
- header("Location: index.php");
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement