Advertisement
gufoe

Secure login PHP and JS

Jun 18th, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. <?php
  2. if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['js'])) {
  3.    
  4.     include('init.php');
  5.     mysql_connect(DB_HOST, DB_USER, DB_PASS);
  6.    
  7.     $user = mysql_real_escape_string($_POST['username']);
  8.     $pass = mysql_real_escape_string($_POST['password']);
  9.    
  10.     if($_POST['js'] == 'off')
  11.         $pass = md5($pass);
  12.    
  13.     $res = mysql_query("SELECT * FROM users WHERE user='$user' AND pass='$pass';");
  14.    
  15.     if(mysql_num_rows($res) == 1) {
  16.         session_start();
  17.         $_SESSION['user'] = mysql_fetch_array($res);
  18.     }
  19.    
  20. }
  21. ?>
  22.  
  23. <form method="get" action="" onsubmit="this.password.value=md5(this.password.value); this.js.value='on';">
  24.     <input type="text" name="username" value="<?php echo (isset($_POST['username']) ? $_POST['username'] : '') ?>">
  25.     <input type="password" name="password" autofocus="">
  26.     <input type="hidden" name="js" value="off">
  27.     <input type="submit" value="Login">
  28. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement