Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- login.php:
- <?php
- session_start();
- ?>
- <!-- Formstuff for login -->
- <form action="/memelord/dologin.php" method="POST">
- Username:<br>
- <input type="text" name="username" /><br>
- Password:<br>
- <input type="password" name="password" /><br><br>
- <input type="submit" value="Login">
- </form>
- Formstuff for account creation
- <b>No account? Make one dumkass:</b>
- <form action="/memelord/register.php" method="POST">
- Username:<br>
- <input type="text" name="username_new" value=""><br><br>
- Password:<br>
- <input type="text" name="password_new" value=""><br><br>
- Repeat password:<br>
- <input type="text" name="password_new2" value=""><br><br>
- <input type="submit" value="Submit">
- </form>
- register.php:
- <?php
- //start session
- session_start();
- //connection stuff goes here:
- include("./db.php");
- DB::connect();
- $username = $_POST["username_new"];
- $password = $_POST["password_new"];
- $hash = password_hash($password, PASSWORD_DEFAULT);
- $stmt = DB::$connection->prepare("INSERT INTO accounts set username=?, password=?");
- $stmt->execute([$username, $hash]);
- header("location: /memelord/login.php");
- ?>
- dologin.php:
- <?php
- //start session
- session_start();
- //connection stuff goes here:
- include("./db.php");
- DB::connect();
- if(isset($_SESSION['login_user'])){ // Checking whether the session is already there or not if
- header("Location: /memelord/index.php"); // true then header redirect it to the home page directly
- }
- // login function
- function login($usr,$pwd){
- $postpwd = $_POST['password'];
- $postusr = $_POST['username'];
- $result = DB::$connection->prepare("SELECT * FROM accounts WHERE username= :hjhjhjh");
- $result->bindParam(':hjhjhjh', $usr);
- $result->execute();
- $users = $result->fetch(0);
- if(isset($users[2])){
- if (password_verify($postpwd, $users[2])) {
- echo "success";// valid login
- } else {
- echo "pwd error";// invalid password
- }
- } else {
- echo "username error";// invalid username
- }
- }
- if($_POST['username'] == '' || $_POST['password'] == ''){
- echo "User not found.";
- session_destroy();
- echo "<br/>Session terminated";
- header("location: /memelord/index.php");
- }
- else{
- login($_POST['username'], $_POST['password']) ;
- }
- ?>
Add Comment
Please, Sign In to add comment