Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] MD5 a skrypt AJAX CHAT
7ad
post
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 18.10.2009

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


Mam problem z porównaniem hasła do md5(hasła).

Jest to fragment orginalnego skryptu


  1. // The code bellow should work without modification for most users
  2. mysql_connect('localhost', $MySQL_username, $MySQL_password);
  3. mysql_select_db($MySQL_database);
  4. $username = isset($username) ? mysql_real_escape_string($username) : '';
  5. $password = isset($password) ? mysql_real_escape_string($password) : '';
  6.  
  7.  
  8. $result = mysql_query("select * from $MySQL_table where $MySQL_username_field = '$username' and ($MySQL_password_field = '$password' or $MySQL_password_field = MD5('$password') or MD5($MySQL_password_field) = '$password' or $MySQL_password_field = MD5(MD5('$password')) or MD5(MD5($MySQL_password_field)) = '$password')");
  9.  
  10. global $chat_data;
  11.  
  12. return mysql_fetch_assoc($result) ||
  13. isset($chat_data['user'][$username]) &&
  14. isset($chat_data['pass'][$username]) &&
  15. ($chat_data['pass'][$username] == ($password));
  16. }
  17.  


Baza haseł jest w MD5, jeśli w okienku logowania wpiszę hasło Md5, to działa.....
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
ikssde
post
Post #2





Grupa: Zarejestrowani
Postów: 217
Pomógł: 40
Dołączył: 20.08.2008

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


Tak musi działać:

  1. // The code bellow should work without modification for most users
  2. mysql_connect('localhost', $MySQL_username, $MySQL_password);
  3. mysql_select_db($MySQL_database);
  4. $username = isset($username) ? mysql_real_escape_string($username) : '';
  5. $password_md5 = isset($password) ? md5($password) : '';
  6. $password = isset($password) ? mysql_real_escape_string($password) : '';
  7.  
  8.  
  9. $result = mysql_query("select * from $MySQL_table where $MySQL_username_field = '$username' and $MySQL_password_field = '$password_md5'");
  10.  
  11. global $chat_data;
  12.  
  13. return mysql_fetch_assoc($result) ||
  14. isset($chat_data['user'][$username]) &&
  15. isset($chat_data['pass'][$username]) &&
  16. ($chat_data['pass'][$username] == ($password_md5));
  17. }


Na samym końcu, w tablicy $chat_data wnioskuję, że hasło przechowujesz w postaci zahashowanej.
Pokaż nam jeszcze kod, który jest odpowiedzialny za zapisywanie hasła do bazy, jak wygląda hashowanie hasła w tamtym miejscu?
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: 9.10.2025 - 15:29