Advertisement
Guest User

Untitled

a guest
May 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.31 KB | None | 0 0
  1. <?php
  2.  
  3. include( "config.php" );
  4.  
  5. mysql_connect( $dbhost, $dbuser, $dbpass ) or die( "Unable to connect!" );
  6. mysql_select_db( $db );
  7.  
  8. if( isset( $_POST['username'] ) && isset( $_POST['password'] ) )
  9. {
  10.     setcookie( "username", mysql_real_escape_string( $_POST['username'] ) );
  11.     setcookie( "password", mysql_real_escape_string( $_POST['password'] ) );
  12.     header( "Location: " . str_ireplace(array( "\b", "\t", "\r", "\n", "%08", "%09", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:" ), "", $_SERVER['PHP_SELF']) );
  13. }
  14. else
  15. {
  16.     if( isset( $_COOKIE['username'] ) && isset( $_COOKIE['password'] ) )
  17.     {
  18.         $query = "SELECT * FROM `members` WHERE username = '" . $_COOKIE['username'] . "' AND password = '" . $_COOKIE['password'] . "'";
  19.         $res = mysql_query( $query ) or die( "Query: " . $query . " failed." );
  20.         $rows = mysql_num_rows( $res );
  21.         if( !$rows )
  22.         {
  23.             die("Username or password invalid!");
  24.         }
  25.         if( isset( $_POST['update'] ) )
  26.         {
  27.             $pass = mysql_real_escape_string( $_POST['new_pass'] );
  28.             $update = "UPDATE members SET password = '" . $pass . "' WHERE username = '" . $_COOKIE['username'];
  29.             mysql_query( $update ) or die( "Unable to update your password, please try again!" );
  30.         }
  31.         else
  32.         {
  33.             $row = mysql_fetch_row( $res );
  34.             ?>
  35.             <div style="text-align: center;">
  36.             <h2>Logged in as: <?= htmlentities( $row[0] ); ?></h2><br /><br />
  37.             <strong>::Change Your Password::</strong>
  38.             <form action="<?= htmlentities( $_SERVER['PHP_SELF'] ); ?>" method="post"><br />
  39.             New Password: <input type="text" name="new_pass" /><br />
  40.             <input type="submit" name="submit" value="::Change Pass::" />
  41.             </form>
  42.             </div>
  43.             <?php
  44.         }
  45.     }
  46.     else
  47.     {
  48.         ?>
  49.         <div style="text-align: center;">
  50.         <strong>::Log In::</strong>
  51.         <form action="<?= htmlentities( $_SERVER['PHP_SELF'] ); ?>" method="post"><br />
  52.         Username: <input type="text" name="username" /><br />
  53.         Password: <input type="password" name="password" /><br />
  54.         <input type="submit" name="submit" value="::Log In::" />
  55.         </form>
  56.         </div>
  57.         <?php
  58.     }
  59. }
  60.  
  61. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement