resetpassword.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Reset a user's password.
  4. *
  5. * This is an admin action that generates a new salt and password
  6. * for a user, then emails the password to the user's registered
  7. * email address.
  8. *
  9. * NOTE: This is different to the "reset password" link users
  10. * can use in that it does not first email the user asking if
  11. * they want to have their password reset.
  12. *
  13. * @package Elgg.Core
  14. * @subpackage Administration.User
  15. */
  16. $guid = get_input('guid');
  17. $user = get_entity($guid);
  18. if (($user instanceof ElggUser) && ($user->canEdit())) {
  19. $password = generate_random_cleartext_password();
  20. if (force_user_password_reset($user->guid, $password)) {
  21. system_message(elgg_echo('admin:user:resetpassword:yes'));
  22. notify_user($user->guid,
  23. elgg_get_site_entity()->guid,
  24. elgg_echo('email:resetpassword:subject', array(), $user->language),
  25. elgg_echo('email:resetpassword:body', array($user->username, $password), $user->language),
  26. array(),
  27. 'email');
  28. } else {
  29. register_error(elgg_echo('admin:user:resetpassword:no'));
  30. }
  31. } else {
  32. register_error(elgg_echo('admin:user:resetpassword:no'));
  33. }
  34. forward(REFERER);