Guest User

Untitled

a guest
Mar 17th, 2017
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.29 KB | None | 0 0
  1. login.php:
  2.  
  3. <?php
  4. session_start();
  5. ?>
  6.  
  7.  
  8.  
  9. <!-- Formstuff for login -->
  10. <form action="/memelord/dologin.php" method="POST">
  11.   Username:<br>
  12.   <input type="text" name="username" /><br>
  13.   Password:<br>
  14.   <input type="password" name="password" /><br><br>
  15.   <input type="submit" value="Login">
  16. </form>
  17.  
  18.  
  19. Formstuff for account creation
  20. <b>No account? Make one dumkass:</b>
  21.  
  22. <form action="/memelord/register.php" method="POST">
  23.   Username:<br>
  24.   <input type="text" name="username_new" value=""><br><br>
  25.   Password:<br>
  26.   <input type="text" name="password_new" value=""><br><br>
  27.    Repeat password:<br>
  28.   <input type="text" name="password_new2" value=""><br><br>
  29.   <input type="submit" value="Submit">
  30. </form>
  31.  
  32. register.php:
  33.  
  34. <?php
  35. //start session
  36. session_start();
  37.  
  38. //connection stuff goes here:
  39. include("./db.php");
  40. DB::connect();
  41.  
  42. $username = $_POST["username_new"];
  43. $password = $_POST["password_new"];
  44. $hash = password_hash($password, PASSWORD_DEFAULT);
  45.  
  46. $stmt = DB::$connection->prepare("INSERT INTO accounts set username=?, password=?");
  47. $stmt->execute([$username, $hash]);
  48.  
  49. header("location: /memelord/login.php");
  50.  
  51. ?>
  52.  
  53. dologin.php:
  54.  
  55. <?php
  56. //start session
  57. session_start();
  58.  
  59. //connection stuff goes here:
  60. include("./db.php");
  61. DB::connect();
  62.  
  63. if(isset($_SESSION['login_user'])){          // Checking whether the session is already there or not if
  64.  header("Location: /memelord/index.php");  // true then header redirect it to the home page directly
  65. }
  66.  
  67.  
  68.  
  69. // login function
  70. function login($usr,$pwd){
  71.  $postpwd = $_POST['password'];
  72.  $postusr = $_POST['username'];
  73.  
  74.  $result = DB::$connection->prepare("SELECT * FROM accounts WHERE username= :hjhjhjh");
  75.   $result->bindParam(':hjhjhjh', $usr);
  76.   $result->execute();
  77.   $users = $result->fetch(0);
  78.   if(isset($users[2])){
  79.     if (password_verify($postpwd, $users[2])) {
  80.         echo "success";// valid login
  81.     } else {
  82.         echo "pwd error";// invalid password
  83.     }
  84.   } else {
  85.     echo "username error";// invalid username
  86.     }
  87.    
  88.   }
  89.  
  90.  
  91. if($_POST['username'] == '' || $_POST['password'] == ''){
  92.     echo "User not found.";
  93.     session_destroy();
  94.     echo "<br/>Session terminated";
  95.     header("location: /memelord/index.php");
  96.  }
  97. else{
  98.   login($_POST['username'], $_POST['password']) ;
  99. }
  100.  
  101. ?>
Add Comment
Please, Sign In to add comment