Advertisement
thebys

W33 - loginform

Dec 3rd, 2011
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <form method="post">
  2. Username: <input type="text" name="username"><br>
  3. Password: <input type="password" name="password">
  4. <input type="submit" name="submited" value="přihlásit">
  5. </form>
  6. <?php
  7. if(isset($_POST['submited']))
  8. {
  9. try{
  10. $query = $dbh->prepare("SELECT * FROM users WHERE login = :username LIMIT 1");
  11. $query->bindParam(':username', $_POST['username'], PDO::PARAM_STR);
  12. $query->execute();
  13. $result = $query->fetchAll();
  14.  
  15. if(!empty($result)){
  16.   foreach($result as $row){
  17.     if(sha1($_POST['password']) == $row['pwdhash'])
  18.       {
  19.         $_SESSION["logged"] = 1;
  20.         $_SESSION["uid"] = $row['uid'];
  21.         $_SESSION["login"] = $row['login'];
  22.         $_SESSION["urole"] = $row['roleid'];
  23.         echo 'Login succesfull as '.$_SESSION["login"].'!';
  24.       }
  25.     else
  26.       {
  27.       echo 'Login failed.';       /*špatné heslo*/
  28.       }
  29.     }
  30. }
  31. else echo 'Login failed.'; /*uživatel neexistuje*/
  32.  
  33. }
  34. catch(PDOException $e)
  35.     {
  36.     echo $e->getMessage();
  37.     }
  38. }
  39.  
  40. ?>
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement