Advertisement
Guest User

Untitled

a guest
May 9th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.83 KB | None | 0 0
  1. "register.php":
  2.  
  3. <?php
  4.  
  5.     include 'config.php';
  6.    
  7.         $username = $_POST['username'];
  8.         $password = $_POST['password'];
  9.         $password2 = $_POST['password2'];
  10.         $confirm = $_POST['1'];
  11.    
  12.     if($password&&$password2==true)
  13.     {
  14.         if($password!=$password2)
  15.         {
  16.             Die("Please make sure the passwords are the same.");
  17.         }
  18.     }
  19.    
  20.     if($username&&$password==true)
  21.     {
  22.         $md5 = md5($password);
  23.         mysql_query("INSERT INTO user (username, password)
  24.         VALUES ('$username', '$md5')");
  25.     }
  26.     Elseif($username==""&&$confirm==true)
  27.     {
  28.         Die("Error: Make sure you enter a username!");
  29.     }
  30.     Elseif($password==""&&$confirm==true)
  31.     {
  32.         Die("Error: Make sure you enter a password!");
  33.     }
  34. ?>
  35. <html>
  36. <body>
  37.  
  38.     <form action="register.php" method="post">
  39.         Username: <input type="text" name="username" /><br>
  40.         Password: <input type="password" name="password" /><br>
  41.         Password again: <input type="password" name="password2" /><br>
  42.         <input type="submit" value="Register!" name="1" />
  43.     </form>
  44.  
  45. </body>
  46. </html>
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55. "login.php":
  56.  
  57. <?php
  58.     include 'config.php';
  59.  
  60.         $password = $_POST['password'];
  61.         $username = $_POST['username'];
  62.         $md5 = md5($password);
  63.         $expire=time()+60*60*24;
  64.    
  65.     $query = mysql_query("SELECT password FROM user WHERE username='$username'");
  66.     echo $query;
  67.     echo $query[0];
  68.     if ($query[0]==$md5)
  69.     {
  70.         setcookie("username", $username, $expire);
  71.         setcookie("password", $md5, $expire);
  72.     }
  73.    
  74.    
  75. ?>
  76.  
  77.  
  78.  
  79.  
  80.  
  81. "index.php":
  82.  
  83. <?php
  84.  
  85.     if(isset($_COOKIE['username']) && isset($_COOKIE['password']))
  86.     {
  87.         echo "test";
  88.     }
  89.    
  90.     echo $_COOKIE['username'] . $_COOKIE['password'];
  91.  
  92. ?>
  93.  
  94. <html>
  95. <body>
  96.  
  97.     <form action="login.php" method="post">
  98.         Username: <input type="text" name="username" /><br>
  99.         Password: <input type="password" name="password" />
  100.         <input type="submit" value="log in" />
  101.     </form>
  102.  
  103. </body>
  104. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement