Guest User

Untitled

a guest
Jun 6th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1. <?php
  2. //check for required fields
  3. if ((!$_POST["username"]) || (!$_POST["password"])) {
  4.     header("Location: userlogin.html");
  5.     exit;
  6. }
  7.  
  8. //connect to server and select database
  9. $conn = mysql_connect("localhost", "calamity", "testpass")
  10.     or die(mysql_error());
  11.  
  12. mysql_select_db("arcade", $conn) or die(mysql_error());
  13.  
  14. #clean the input strings
  15. $user =  mysql_real_escape_string($_POST['username']);
  16. #hash the pass, be sure to use the same hashed password when inserting
  17. $pass = mysql_real_escape_string(crypt($_POST['password'],'someverylongsalt'));
  18.  
  19. $sql = "select f_name, l_name from auth_users where username = '$user' AND password = '$pass'";
  20. $result = mysql_query($sql,$conn) or die(mysql_error());
  21.  
  22. //get the number of rows in the result set, should be one if match
  23. if (mysql_num_rows($result) == 1) {
  24.  
  25.     //if authorised get the values of f_name l_name
  26.     $f_name = mysql_result($result, 0, 'f_name');
  27.     $l_name = mysql_result($result, 0, 'l_name');
  28.  
  29.     //set auth cookie
  30.     setcookie("auth", "1", 0, "/", "localhost", 0);
  31.    
  32.     //create display string
  33.     $display_block = "<p>$f_name $l_name is authorized!</p>
  34.     <p>Authorised Users' Menu:
  35.     <ul>
  36.     <li><a href=\"secretpage.php\">secret page</a>
  37.     </ul>";
  38.  
  39. } else {
  40.  
  41.     //redirect back to login form if not authorised
  42.     header("Location: userlogin.html");
  43.     exit;
  44. }
  45. ?>
  46.  
  47. <html>
  48. <head>
  49. <title>user login</title>
  50. </head>
  51. <body>
  52. <? echo $display_block; ?>
  53. </body>
  54. </html>
Add Comment
Please, Sign In to add comment