Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Logowanie
Hectic
post
Post #1





Grupa: Zarejestrowani
Postów: 256
Pomógł: 7
Dołączył: 1.01.2005

Ostrzeżenie: (0%)
-----


Czy może mi ktoś powiedzieć czy jest to poprawny kod funkcji logowania?

  1. <?
  2. $login=$_POST['login'];
  3. $password = md5($_POST['password']);
  4.  
  5. $result = mysql_query ("SELECT password FROM `admin` WHERE login = '$login' "); // pobranie hasła do podanego loginu
  6. $pas = mysql_fetch_array($result);
  7.  
  8.  
  9.  
  10. <form method="post">
  11. <table border="0" cellspacing="0" cellpadding="0">
  12. <tr>
  13. <td height="5"></TD>
  14. </tr>
  15. <tr>
  16. <td>Login: </td>
  17. <td width="5"></td>
  18. <td colspan="2"><input type="Text" name="login"></td>
  19. </tr>
  20. <tr>
  21. <td height="5"></TD>
  22. </tr>
  23. <tr>
  24. <td>Hasło: </td>
  25. <td width="5"></td>
  26. <td><input type="password" name="password"></td>
  27. </tr>
  28. <tr>
  29. <td height="5"></TD>
  30. </tr>
  31. <tr>
  32. <td colspan="3" align="center"><input type="Submit" name="submit" value="Wyślij"></td>
  33. </tr>
  34. </table></form>';
  35.  
  36. if ($password == $pas['password'])
  37.  
  38. echo'Hasło ok';
  39.  
  40. else 
  41.  
  42. echo 'Złe hasło';
  43. ?>


////Edit

hasło jest kodowane w MD5 (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)

Ten post edytował Hectic 1.03.2006, 15:03:45
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
qbejs
post
Post #2





Grupa: Zarejestrowani
Postów: 48
Pomógł: 1
Dołączył: 9.02.2006

Ostrzeżenie: (0%)
-----


Masz tu mój sprawdzony system (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) Jedyne co musisz zrobić to ustanowić połączenie z bazą i w sumie tyle (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) Dodatkowo skrypt obsługuje obsługę zapamiętywania usera oraz poziomy dostępu ( pole level ).

  1. <?php
  2. if (isset($_POST['loginsend']))
  3. {
  4. //$cookie=$_POST['save'];
  5. $login=htmlspecialchars(trim($_POST['login']));
  6. $check_login=mysql_query("SELECT login FROM `user_test` WHERE login='".$login."'");
  7. $login_result=mysql_fetch_array($check_login);
  8. if ($login_result['login'] = 1)
  9. {
  10. $login=htmlspecialchars(trim($_POST['login']));
  11. $pass=md5(md5($_POST['pass']));
  12. $check_user=mysql_query("SELECT count(*) FROM `user_test` WHERE login='".$login."' AND pass='".$pass."';");
  13. $if_ok=mysql_result($check_user, 0);
  14. if ($if_ok == 1)
  15. {
  16. $session_data="SELECT * FROM `user_test` WHERE login='".$login."'";
  17. $result=mysql_fetch_array(mysql_query($session_data));
  18. session_register('login');
  19. $_SESSION['login']=$_POST['login'];
  20. session_register('level');
  21. $_SESSION['level']=$result['level'];
  22. //echo '<META HTTP-EQUIV="refresh" CONTENT="3" URL="done.php">';
  23. echo 'Zalogowano pomyslnie - nastapi przeladowanie strony...';
  24.  
  25. $cookie=$_POST['save'];
  26. if ($cookie = 1)
  27. {
  28.  $dane=$login.'|'.$pass;
  29.  setcookie ("dane", $dane,time()+3600*24*365);
  30. }
  31. }
  32. }
  33. else
  34. print "Nie ma takiego użytkonika !";
  35.  
  36.  
  37.  
  38.  
  39.  
  40. }else
  41. include ('login.php');
  42.  
  43. ?>


Ten post edytował qbejs 1.03.2006, 22:29:24
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.12.2025 - 05:10