Advertisement
Guest User

DomainAgent 0.3 login.php fixed

a guest
Jun 18th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. <?php
  2. require_once (__DIR__ . '/includes/includes.php');
  3. require_once ('includes/classes/PasswordHash.php');
  4. $hasher = new PasswordHash(8, TRUE); // initialize the PHPass class
  5.  
  6. if(!empty($_POST))
  7. {
  8.     try
  9.     {
  10.         $conn = DB::getConnection()->prepare("SELECT user_name, user_pass
  11.                                              FROM users
  12.                                              WHERE user_name = :username");
  13.         $result = $conn->execute(array(':username' => $_POST['username']));
  14.     }
  15.     catch(PDOException $ex)
  16.     {
  17.         die('Cannot retrieve user data.');
  18.     }
  19.     $login_ok = false;
  20.     $row = $conn->fetch();
  21.     if($row)
  22.     {
  23.         $password=$_POST['password'];
  24.         $hashed=$row['user_pass'];
  25.         if ($hasher->CheckPassword($password, $hashed)) {
  26.             $login_ok=true;
  27.         }
  28.     }
  29.     if($login_ok)
  30.     {
  31.         $_SESSION['user'] = $row;
  32.         header("Location: index.php");
  33.         die("Redirecting to: index.php");
  34.     }
  35.     else
  36.     {
  37.         $comment='Error: wrong username or password';
  38.     }
  39. }
  40. ?>
  41. <html>
  42. <head>
  43.     <title>DomainAgent - Login</title>
  44. </head>
  45. <body>
  46.     <div style="width:300px; margin: 0 auto; text-align: center; margin-top: 50px;">
  47.         <h1>Login</h1>
  48.         <?php if (isset($comment)) echo $comment.'<br/><br/>'; ?>
  49.         <form action="login.php" method="post">
  50.             Username:<br />
  51.             <input type="text" name="username" value="" />
  52.             <br /><br />
  53.             Password:<br />
  54.             <input type="password" name="password" value="" />
  55.             <br /><br />
  56.             <input type="submit" value="Login" />
  57.         </form>
  58.     </div>
  59. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement