Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Logowanie i rejestracja
Forum PHP.pl > Forum > PHP
michu9010
witam,
jakis czas temu znalazlem w sieci system logowania i rejestracji i mam problem z zmiana hasla i edytowaniem danych
to sa te funkcje (formularz):
  1. function show_changepassword_form(){
  2.  
  3. echo '<form action="index.php?com=changepassword" method="post">
  4. <fieldset>
  5. <legend>Change Password</legend>
  6. <input type="hidden" value="'.$_SESSION['username'].'" name="username">
  7. <dl>
  8. <dt>
  9. <label for="oldpassword">Aktualne haslo:</label>
  10. </dt>
  11. <dd>
  12. <input name="oldpassword" type="password" id="oldpassword" maxlength="15">
  13. </dd>
  14. <dt>
  15. <label for="password">Nowe haslo:</label>
  16. </dt>
  17. <dd>
  18. <input name="password" type="password" id="password" maxlength="15">
  19. </dd>
  20. <dt>
  21. <label for="password2">Potwierdz nowe haslo:</label>
  22. </dt>
  23. <dd>
  24. <input name="password2" type="password" id="password2" maxlength="15">
  25. </dd>
  26. </dl>
  27. <p>
  28. <input name="reset" type="reset" value="Wyczysc">
  29. <input name="change" type="submit" value="Zmien">
  30. </p>
  31. </fieldset>
  32. </form>
  33. ';
  34. }

dane personalne
  1. function show_update_form(){
  2. echo '<form action="index.php?com=changeprofile" method="get">
  3. <fieldset><legend>Edycja danych</legend>
  4. <label for="data" id="personal">Dane personalne</label>
  5. <dl>
  6. <dt><label for="name">Imie:</label></dt>
  7. <dd><input name="name" type="text" id="name" size="25" maxlength="10" /></dd>
  8. <dt><label for="surname">Nazwisko:</label></dt>
  9. <dd><input name="surname" type="text" id="surname" size="25" maxlength="30" /></dd>
  10. <dt><label for="telephone">Numer telefonu:</label></dt>
  11. <dd>+48<input name="telephone" type="text" id="telephone" size="21" maxlength="12"></dd>
  12. <dt><label for="gg">Numer Gadu-Gadu:</label></dt>
  13. <dd><input name="gg" type="text" id="gg" size="25" maxlength="9" /></dd>
  14. </dl>
  15. <label for="address" id="personal">Dane adresowe</label>
  16. <dl>
  17. <dt><label for="street">Ulica:</label></dt>
  18. <dd><input name="street" type="text" id="street" size="25" maxlength="30" /></dd>
  19. <dt><label for="nrhouse">Numer domu (XX/XX):</label></dt>
  20. <dd><input name="nrhouse" type="text" id="nrhouse" size="25" maxlength="6" /></dd>
  21. <dt><label for="postcode">Kod pocztowy(XX-XXX):</label></dt>
  22. <dd><input name="postcode" type="text" id="postcode" size="25" maxlength="6" /></dd>
  23. <dt><label for="province">Województwo:</label></dt>
  24. <dd>
  25. <select name="province" id="province">
  26. <option>dolnoslaskie</option>
  27. <option>kujawsko-pomorskie</option>
  28. <option>lubelskie</option>
  29. <option>lubuskie</option>
  30. <option>lódzkie</option>
  31. <option>malopolskie</option>
  32. <option>mazowieckie</option>
  33. <option>opolskie</option>
  34. <option>podkarpackie</option>
  35. <option>podlaskie</option>
  36. <option>pomorskie</option>
  37. <option>slaskie</option>
  38. <option>swietokrzyskie</option>
  39. <option>warminsko-mazurskie</option>
  40. <option>wielkopolskie</option>
  41. <option>zachodniopomorskie</option>
  42. </select>
  43. </dd>
  44. </dl>
  45. <p>
  46. <input type="reset" name="reset" value="Wyczysc" />
  47. <input name="update" type="submit" value="Zapisz" />
  48. </p>
  49. </fieldset>
  50. </form>';
  51. }

plik zmiany hasla
  1. <?php
  2.  
  3.  
  4.  
  5. if (isLoggedIn() == true)
  6. {
  7.  
  8. if (isset($_POST['change']))
  9. {
  10.  
  11. if (changePassword($_POST['username'], $_POST['oldpassword'], $_POST['password'],
  12. $_POST['password2']))
  13. {
  14. echo "Twoje haslo zostalo zmienione! <br /> <a href='./index.php'>Strona glówna</a>";
  15.  
  16. } else
  17. {
  18. echo "Haslo nie zostalo zmienione, spróbuj jeszcze raz.";
  19. show_update_form();
  20. }
  21.  
  22. } else
  23. {
  24. show_update_form();
  25. }
  26.  
  27. } else {
  28. // user is not loggedin
  29. show_loginform();
  30. }
  31.  
  32. ?>

i zmiany dancyh
  1. <?php
  2.  
  3.  
  4.  
  5. if (isLoggedIn() == true)
  6. {
  7.  
  8. if (isset($_POST['update']))
  9. {
  10.  
  11. if (update($_POST['name'], $_POST['surname'], $_POST['telephone']))
  12. {
  13. echo "Twoje dane zostały zapisane! <br /> <a href='./index.php'>Strona glówna</a>";
  14.  
  15. } else
  16. {
  17. echo "Dane niezostały zapisane, spróbuj jeszcze raz.";
  18. show_update_form();
  19. }
  20.  
  21. } else
  22. {
  23. show_update_form();
  24. }
  25.  
  26. } else {
  27. // user is not loggedin
  28. show_loginform();
  29. }
  30.  
  31. ?>

i plik odpowiedzialny za dzialania dla uzytkownika
  1.  
  2. ##### User Functions #####
  3.  
  4. function changePassword($username,$currentpassword,$newpassword,$newpassword2){
  5. global $seed;
  6. if (!valid_username($username) || !user_exists($username))
  7. {
  8. return false;
  9. }
  10. if (! valid_password($newpassword) || ($newpassword != $newpassword2)){
  11.  
  12. return false;
  13. }
  14.  
  15. // we get the current password from the database
  16. $query = sprintf("SELECT password FROM login WHERE username = '%s' LIMIT 1",
  17.  
  18. $result = mysql_query($query);
  19. $row= mysql_fetch_row($result);
  20.  
  21. // compare it with the password the user entered, if they don't match, we return false, he needs to enter the correct password.
  22. if ($row[0] != sha1($currentpassword.$seed)){
  23.  
  24. return false;
  25. }
  26.  
  27. // now we update the password in the database
  28. $query = sprintf("update login set password = '%s' where username = '%s'",
  29. mysql_real_escape_string(sha1($newpassword.$seed)), mysql_real_escape_string($username));
  30.  
  31. if (mysql_query($query))
  32. {
  33. return true;
  34. }else {return false;}
  35. return false;
  36. }
  37.  
  38.  
  39. function user_exists($username)
  40. {
  41. if (!valid_username($username))
  42. {
  43. return false;
  44. }
  45.  
  46. $query = sprintf("SELECT loginid FROM login WHERE username = '%s' LIMIT 1",
  47.  
  48. $result = mysql_query($query);
  49.  
  50. if (mysql_num_rows($result) > 0)
  51. {
  52. return true;
  53. } else
  54. {
  55. return false;
  56. }
  57.  
  58. return false;
  59.  
  60. }
  61.  
  62. function activateUser($uid, $actcode)
  63. {
  64.  
  65. $query = sprintf("select activated from login where loginid = '%s' and actcode = '%s' and activated = 0 limit 1",
  66.  
  67. $result = mysql_query($query);
  68.  
  69. if (mysql_num_rows($result) == 1)
  70. {
  71.  
  72. $sql = sprintf("update login set activated = '1' where loginid = '%s' and actcode = '%s'",
  73.  
  74. if (mysql_query($sql))
  75. {
  76. return true;
  77. } else
  78. {
  79. return false;
  80. }
  81.  
  82. } else
  83. {
  84.  
  85. return false;
  86.  
  87. }
  88.  
  89. }
  90.  
  91. function registerNewUser($username, $password, $password2, $email)
  92. {
  93.  
  94. global $seed;
  95.  
  96. if (!valid_username($username) || !valid_password($password) ||
  97. !valid_email($email) || $password != $password2 || user_exists($username))
  98. {
  99. return false;
  100. }
  101.  
  102.  
  103. $code = generate_code(20);
  104. $sql = sprintf("insert into login (username,password,email,actcode) value ('%s','%s','%s','%s')",
  105. mysql_real_escape_string($username), mysql_real_escape_string(sha1($password . $seed))
  106.  
  107.  
  108. if (mysql_query($sql))
  109. {
  110. $id = mysql_insert_id();
  111.  
  112. if (sendActivationEmail($username, $password, $id, $email, $code))
  113. {
  114.  
  115. return true;
  116. } else
  117. {
  118. return false;
  119. }
  120.  
  121. } else
  122. {
  123. return false;
  124. }
  125. return false;
  126.  
  127. }
  128.  
  129. function lostPassword($username, $email)
  130. {
  131.  
  132. global $seed;
  133. if (!valid_username($username) || !user_exists($username) || !valid_email($email))
  134. {
  135.  
  136. return false;
  137. }
  138.  
  139. $query = sprintf("select loginid from login where username = '%s' and email = '%s' limit 1",
  140. $username, $email);
  141.  
  142. $result = mysql_query($query);
  143.  
  144. if (mysql_num_rows($result) != 1)
  145. {
  146.  
  147. return false;
  148. }
  149.  
  150.  
  151. $newpass = generate_code(8);
  152.  
  153. $query = sprintf("update login set password = '%s' where username = '%s'",
  154. mysql_real_escape_string(sha1($newpass.$seed)), mysql_real_escape_string($username));
  155.  
  156. if (mysql_query($query))
  157. {
  158.  
  159. if (sendLostPasswordEmail($username, $email, $newpass))
  160. {
  161. return true;
  162. } else
  163. {
  164. return false;
  165. }
  166.  
  167. } else
  168. {
  169. return false;
  170. }
  171.  
  172. return false;
  173.  
  174. }
  175.  
  176. function update($name, $surname, $telephone){
  177. global $seed;
  178. if (empty($name) || empty($surname) || empty($telephone))
  179. {
  180. return false;
  181. }
  182.  
  183. // we get the current password from the database
  184. $query = sprintf("SELECT name, surname, telephone FROM login WHERE username = '%s' LIMIT 1",
  185.  
  186. $result = mysql_query($query);
  187. $row= mysql_fetch_row($result);
  188.  
  189. // now we update the personal in the database
  190. $query = sprintf("update login set name = '%name', surname ='$surname', telephone = '$telephone' where username = '%s'",
  191.  
  192. if (mysql_query($query))
  193. {
  194. return true;
  195. }else {return false;}
  196. return false;
  197. }


pomoze mi ktos bo nie wiem co jest nie tak ;/;/ a przy aktualizacji dancyh personalnych pojawia sie dziwny link
Kod
http://www.mija.unl.pl/index.php?name=michu&surname=jastrzebski&telephone=663310897&gg=&street=&nrhouse=&postcode=&province=dolnoslaskie&update=Zapisz


a przy probie zmiany hasla komuniat haslo nie zostalo zmienione licze na Wasze pomysly i duza cierpliwosc dla mnie smile.gif

pozdrawiam michu9010

a zachowanie skryptu mozna zobaczyc na www.mija.unl.pl

login michu9010 pass michu9010
blooregard
Zapoznaj się proszę z tym tematem:
Temat: Jak poprawnie zada pytanie
michu9010
odnosnie zmiany hasla juz nie aktualne smile.gif
tylko pozostaje problem aktualizacji dancyh
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.