Advertisement
turlando

Untitled

Jun 11th, 2011
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.29 KB | None | 0 0
  1. <?php
  2.  
  3.     $database['host']   =   '127.0.0.1';
  4.     $database['user']   =   'user';
  5.     $database['pass']   =   'database';
  6.     $database['db']     =   'password';
  7.  
  8.     try {
  9.         $DBH = new PDO("mysql:host=$database[host];dbname=$database[db]", $database['user'], $database['pass']);
  10.     } catch(PDOException $e) {
  11.         $error['db-link'] = $e->getMessage();
  12.     }
  13.  
  14.     session_start();
  15.  
  16.     function login()
  17.     {
  18.  
  19.         if (isSet($_SESSION['username']) && isSet($_SESSION['password'])) {
  20.             $STH = $DBH->prepare('SELECT username, password FROM accounts WHERE username = ? AND password = ?');
  21.             $STH->execute(Array($_SESSION['username'], $_SESSION['password']));
  22.             $STH->setFetchMode(PDO::FETCH_ASSOC);
  23.             if ($TH->fetchColumn() == 0) {
  24.                 return 'attack'; /* wtf are you doin? */
  25.             } else {
  26.                 return 'logged'; /* user and pass ok */
  27.             }
  28.         }
  29.  
  30.         if (isSet($_POST['username']) && isSet($_POST['password'])) {
  31.             $password = md5($_POST['password']);
  32.             $STH = $DBH->prepare('SELECT username, password FROM accounts WHERE username = ? AND password = ?');
  33.             $STH->execute(Array($_POST['username'], $password));
  34.             $STH->setFetchMode(PDO::FETCH_ASSOC);
  35.             if ($STH->fectchColumn() > 0) {
  36.                 $_SESSION['username'] = $_POST['username'];
  37.                 $_SESSION['password'] = $password;
  38.                 return 'logged'; /* user and pass ok */
  39.             } else {
  40.                 return 'notcorrect'; /* user and pass not ok */
  41.             }
  42.         }
  43.  
  44.         if (empty($_POST['username']) && empty($_POST['password']) && empty($_SESSION['username']) && empty($_SESSION['password'])) {
  45.             return 'nologin'; /* have to do the login */
  46.         }
  47.  
  48.     }
  49.  
  50.  
  51.     function login_form()
  52.     {
  53. ?>
  54.         <form method="post" action="<?php echo $config['url']; ?>/login" id="login">
  55.             <fieldset>
  56.                 <legend>Login</legend>
  57.                     <label>Username: <input type="text" name="username" required /></label>
  58.                     <label>Password: <input type="password" name="password" required /></label>
  59.                     <input type="submit" />
  60.             </fieldset>
  61.         </form>
  62. <?php
  63.     }
  64.  
  65.     function module_content()
  66.     {
  67.         if (login() == 'login') {
  68.             header('Location: '.$config['url'].'/dashboard');
  69.         } else if (login() == 'notcorrect') {
  70. ?>
  71.             <p>Sorry, login not correct. Please, try again.</p>
  72. <?php
  73.             login_form();
  74.         } else if (login() == 'attack') {
  75.             login_form();
  76.         } else if (login() == 'nologin') {
  77.             login_form();
  78.         }
  79.     }
  80.  
  81.  
  82.     module_content();
  83.  
  84. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement