Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> przypomnienie hasła użytkownikowi kłopot z kodem
cryptonim
post
Post #1





Grupa: Zarejestrowani
Postów: 16
Pomógł: 0
Dołączył: 30.05.2010

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


witam, mam kod służący przypomnienia użytkownikowi o jego haśle jeśli go zapomni,Wszystko działa prawidłowo tzn. dostaje wiadomość na maila itd, ale w miejscu gdzie ma być podane jego hasło jest luka i nie potrafię sobie z tym poradzić może wam się uda znależć rozwiązanie . oto kod:

  1.  
  2. <?
  3. include 'db.php';
  4.  
  5. switch($_POST['recover']){
  6. default:
  7. include 'lost_pw.html';
  8. break;
  9.  
  10. case "recover":
  11. recover_pw($_POST['email_address']);
  12. break;
  13. }
  14. function recover_pw($email_address){
  15. if(!$email_address){
  16. echo "You forgot to enter your Email address !!<br />";
  17. include 'lost_pw.html';
  18. exit();
  19. }
  20. // quick check to see if record exists
  21. $sql_check = mysql_query("SELECT * FROM users WHERE email_address='$email_address'");
  22. $sql_check_num = mysql_num_rows($sql_check);
  23. if($sql_check_num == 0){
  24. echo "No records found matching your email address<br />";
  25. include 'lost_pw.html';
  26. exit();
  27. }
  28. // Everything looks ok, update it and send it!
  29.  
  30.  
  31.  
  32. $db_password = md5($password);
  33.  
  34. $sql = mysql_query("UPDATE users SET password='$db_password' WHERE email_address='$email_address'");
  35.  
  36. $subject = "Your Password at MyWebsite!";
  37. $message = "Hi $first_name your username and password is.
  38.  
  39. Username:$username
  40. Password:$password
  41.  
  42. <a href="http://www.cos-tam.pl/login_form.html" target="_blank">http://www.cos-tam.pl/login_form.html</a>
  43.  
  44. Thanks!
  45. The Webmaster
  46.  
  47. This is an automated response, please do not reply!";
  48.  
  49. mail($email_address, $subject, $message, "From: costam<costam@o2.pl>\nX-Mailer: PHP/" . phpversion());
  50. include 'password.html';
  51. }
  52. ?>
  53.  
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
cryptonim
post
Post #2





Grupa: Zarejestrowani
Postów: 16
Pomógł: 0
Dołączył: 30.05.2010

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


ok dzieki za info (IMG:style_emoticons/default/smile.gif)

Zrobiłem tak napisalem kod ktory wysyła uzytkownikowi losowo wygenerowane hasło, poznej moze je sobie zmienic kod moze sie komu przyda :

  1.  
  2. <?
  3.  
  4. include 'db.php';
  5.  
  6.  
  7.  
  8. switch($_POST['recover']){
  9.  
  10. default:
  11.  
  12. include 'lost_pw.html';
  13.  
  14. break;
  15.  
  16.  
  17.  
  18. case "recover":
  19.  
  20. recover_pw($_POST['email_address']);
  21.  
  22. break;
  23.  
  24. }
  25.  
  26. function recover_pw($email_address){
  27.  
  28. if(!$email_address){
  29.  
  30. echo "You forgot to enter your Email address !!<br />";
  31.  
  32. include 'lost_pw.html';
  33.  
  34. exit();
  35.  
  36. }
  37.  
  38.  
  39.  
  40. $sql_check = mysql_query("SELECT * FROM users WHERE email_address='$email_address'");
  41.  
  42. $sql_check_num = mysql_num_rows($sql_check);
  43.  
  44. if($sql_check_num == 0){
  45.  
  46. echo "No records found matching your email address<br />";
  47.  
  48. include 'lost_pw.html';
  49.  
  50. exit();
  51.  
  52. }
  53.  
  54. !
  55.  
  56.  
  57.  
  58. function makeRandomPassword() {
  59.  
  60. $salt = "abchefghjkmnpqrstuvwxyz0123456789";
  61.  
  62. srand((double)microtime()*1000000);
  63.  
  64. $i = 0;
  65.  
  66. while ($i <= 7) {
  67.  
  68. $num = rand() % 33;
  69.  
  70. $tmp = substr($salt, $num, 1);
  71.  
  72. $pass = $pass . $tmp;
  73.  
  74. $i++;
  75.  
  76. }
  77.  
  78. return $pass;
  79.  
  80. }
  81.  
  82.  
  83.  
  84. $random_password = makeRandomPassword();
  85.  
  86.  
  87.  
  88. $db_password = md5($random_password);
  89.  
  90.  
  91.  
  92. $sql = mysql_query("UPDATE users SET password='$db_password' WHERE email_address='$email_address'");
  93.  
  94.  
  95.  
  96. $subject = "Your Password at MyWebsite!";
  97.  
  98. $message = "Hi, we have reset your password.
  99.  
  100.  
  101.  
  102. New Password: $random_password
  103.  
  104.  
  105.  
  106. <a href="http://www.costam.com/login_form.html" target="_blank">http://www.costam.com/login_form.html</a>
  107.  
  108.  
  109.  
  110. Thanks!
  111.  
  112. The Webmaster
  113.  
  114.  
  115.  
  116. This is an automated response, please do not reply!";
  117.  
  118.  
  119.  
  120. mail($email_address, $subject, $message, "From: costam<costam@o2.pl>\nX-Mailer: PHP/" . phpversion());
  121.  
  122. include 'password.html';
  123.  
  124. }
  125.  
  126. ?>
  127.  




aha jak moge zmienic kolor czcionki tego hasła bo cos niemoge wykombinowac heh (IMG:style_emoticons/default/smile.gif) !?
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: 17.10.2025 - 21:13