Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. <?php
  2.     session_start();
  3.     require 'mysql.php';
  4.     if ( isset($_POST['login']) && $_POST['username']!=' ' )
  5.     {
  6.         $usr = $_POST['username'];
  7.         $query = "SELECT * FROM users WHERE username='$usr'";
  8.         $result = mysql_query($query) or
  9.             die(mysql_error());
  10.         if ( $row = mysql_fetch_array($result) )
  11.         {
  12.             if ( $row['password'] == md5("asdf".md5($_POST['password'])) )
  13.             {
  14.                 $_SESSION['username']=$usr;
  15.                 $_SESSION['auth']=true;
  16.                 echo 'Redirecting to main page';
  17.             }
  18.             else
  19.                 echo 'Password does not match!';
  20.         }
  21.         else
  22.             echo 'User does not exist! <a href="newaccount.php">Create new account</a>';
  23.     }
  24. ?>
  25. <html>
  26. <head>
  27. <title>Login</title>
  28. </head>
  29. <body>
  30. <?php
  31.     if ( !isset($_SESSION['auth']) || $_SESSION['auth']=false )
  32.     {
  33.         echo '<form action="login.php" method="POST">';
  34.         echo 'Username: <input type="text" name="username" /><br />';
  35.         echo 'Password: <input type="password" name="password" /><br />';
  36.         echo '<input type="submit" name="login" value="Log in"></form>';
  37.     }
  38. ?>
  39. </body>
  40. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement