Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Przypomnienie hasła
inny02
post 19.09.2009, 13:57:38
Post #1





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 24.08.2009

Ostrzeżenie: (10%)
X----


Witam,

chcę dodać do tego istniejącego kodu, przypomnienie hasła, gdy hasło będzie kodowane w bazie.
Skrypt wysyła na email zapomniane hasło z bazy w formie jawnej, a jak tutaj dodać, jeśli użytkownik wyśle formularz przypomnienia hasła to:
generuje losowe hasło, następnie hasło haszuje w md5 i zapisuje w bazie.
Hasło to losowe(ale hasło przed z haszowaniem) wysyła na email, użytkownik może już się zalogować przez nowe hasło.

  1. if (isset($_POST["forgot"])) {
  2. $username = htmlspecialchars(trim($_POST["username"]));
  3. $email = htmlspecialchars(trim($_POST["email"]));
  4.  
  5. if (($username != "") || ($email != ""))
  6. {
  7. if ($username != "")
  8. $q = "SELECT * FROM `members` WHERE username = '$username'";
  9. else
  10. $q = "SELECT * FROM `members` WHERE email = '$email'";
  11.  
  12.  
  13. if(!($result_set = mysql_query($q))) die(mysql_error());
  14. $number = mysql_num_rows($result_set);
  15.  
  16. if (!$number) {
  17. echo "Sorry ! No account with the specified username or email exists";
  18. showForm();
  19. }
  20. else {
  21. $r = mysql_fetch_array($result_set);
  22. $email1 = $r['email'];
  23. $username = $r['username'];
  24. $password = $r['password'];
  25.  
  26.  
  27. $to = $email1;
  28. $subject = "$webtitle - Password Recovery";
  29. $body = "Hello $username, \n\nYou requested for your $webtitle account password recovery.\nYour registration information is shown below:\n\nUser: $username\nPass: $password\n\nThanks!\n{$website}";
  30. $headers = "From: $webtitle <{$website}>";
  31.  
  32.  
  33. if (mail ($to, $subject, $body, $headers))
  34. echo "An email has been sent with your password to the email address you specified during registration.";
  35. else
  36. { echo "Sorry ! The password recovery email could not be sent due to some reason."; showForm(); }
  37.  
  38. }
  39. }
  40. else
  41. { echo "Please give a username or email atleast !"; showForm(); }
  42. }
  43. else
  44. {
  45. if ($session == false)
  46. showForm();
  47. else
  48. echo "Sorry ! You are already logged in.";
  49. }


wiem, że trzeba użyć funkcji do generowania jakieś ciągu, UPDATE do bazy itd. tylko nie potrafię tego dołączyć do istniejącego kodu php.

Z góry dzięki za pomoc

Pozdrawiam
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 06:06