Guest User

Untitled

a guest
Jun 10th, 2017
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.44 KB | None | 0 0
  1. <head>
  2.   <meta charset="utf-8">
  3.   <meta http-equiv="x-ua-compatible" content="ie=edge">
  4.   <meta name="description" content="">
  5.   <meta name="viewport" content="width=device-width, initial-scale=1">
  6.   <title>Check Code</title>
  7.   <link rel="stylesheet" href="css/normalize.css">
  8.   <link rel="stylesheet" href="css/main.css">
  9. </head>
  10.  
  11. <center>
  12.   <form action="login.php" method="post">
  13.     <h2>Check Code</h2>
  14.     <p>
  15.       <span>Username:</span>
  16.       <input name="username" type="text" />
  17.       <br/>
  18.       <br/>
  19.       <span> Password:</span>
  20.       <input name="password" type="password" />
  21.       <br/>
  22.       <br/>
  23.       <input name="go" type="submit" value="send" />
  24.       <input name="reset" type="reset" value="clear" />
  25.       <br/><br/>
  26.       <a href="index.php">Mainpage</a>
  27.     </p>
  28.     <p>
  29.       <?php
  30.  
  31.         $username = "";
  32.         $username = isset($_POST['username']) ? $_POST['username'] : '';
  33.         $password = "";
  34.         $password = isset($_POST['password']) ? $_POST['password'] : '';
  35.         $cookiecode = "";
  36.  
  37.         try
  38.         {
  39.           $db_auth = parse_ini_file("/srv/foodbar/.db_auth");
  40.           $db = pg_connect("host=$db_auth[DB_HOST] port=5432 dbname=postgres user=$db_auth[DB_USER] password=$db_auth[DB_PASSWORD]");
  41.  
  42.           if($username != "")
  43.           {
  44.             $query="SELECT * FROM foodbar.users WHERE username = '$username' AND password = '$password'";
  45.             $result = pg_query($query);
  46.  
  47.             if(pg_num_rows($result) > 0)
  48.             {
  49.               $is_login = true;
  50.               $query="SELECT cookiecode FROM foodbar.users WHERE password = '$password' AND username = '$username'";
  51.               $row = pg_fetch_assoc(pg_query($query));
  52.               $cookiecode = $row['cookiecode'];
  53.  
  54.               echo 'Your code for a free cookie is:<br>';
  55.               echo $cookiecode;
  56.               echo '<br>';
  57.               echo 'Incorrect? <a href="forgot.php">click</a>';
  58.             }
  59.             else
  60.             {
  61.               echo "Username or Password is wrong. <br>  Fill in again.";
  62.             }
  63.           }
  64.           else
  65.           {
  66.             echo "Please fill in all fields!";
  67.             echo '<br>';
  68.             echo 'Forgot your password? <a href="forgot.php">Click Me</a>';
  69.           }
  70.  
  71.         }
  72.         catch (PDOException $e)
  73.         {
  74.           print ($e->getMessage());
  75.           return false;
  76.         }
  77.       ?>
  78.     </p>
  79.   </form>
  80. </center>
Add Comment
Please, Sign In to add comment