pwd_reset.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. # enhancement for plugin user model
  3. if (!defined('CLASS_USER')) {
  4. define('CLASS_USER', 'User');
  5. }
  6. /**
  7. * reset user passwords
  8. * 2011-08-01 ms
  9. */
  10. class PwdResetShell extends Shell {
  11. var $tasks = array();
  12. //var $uses = array('User');
  13. var $Auth = null;
  14. /**
  15. * reset all pwds to a simply pwd (for local development)
  16. * 2011-08-01 ms
  17. */
  18. function main() {
  19. $components = array('AuthExt', 'Auth');
  20. foreach ($components as $component) {
  21. if (App::import('Component', $component)) {
  22. $component .='Component';
  23. $this->Auth = new $component();
  24. break;
  25. }
  26. }
  27. if (!is_object($this->Auth)) {
  28. $this->out('No Auth Component found');
  29. die();
  30. }
  31. $this->out('Using: '.get_class($this->Auth).' (Abort with STRG+C)');
  32. if (!empty($this->args[0]) && mb_strlen($this->args[0]) >= 2) {
  33. $pwToHash = $this->args[0];
  34. }
  35. while (empty($pwToHash) || mb_strlen($pwToHash) < 2) {
  36. $pwToHash = $this->in(__('Password to Hash (2 characters at least)', true));
  37. }
  38. $this->hr();
  39. $this->out('pwd:');
  40. $this->out($pwToHash);
  41. $pw = $this->Auth->password($pwToHash);
  42. $this->hr();
  43. $this->out('hash:');
  44. $this->out($pw);
  45. $this->hr();
  46. $this->out('resetting...');
  47. $this->User = ClassRegistry::init(CLASS_USER);
  48. if (!$this->User->hasField('password')) {
  49. $this->error(CLASS_USER.' model doesnt have a password field!');
  50. }
  51. if (method_exists($this->User, 'escapeValue')) {
  52. $newPwd = $this->User->escapeValue($pw);
  53. } else {
  54. $newPwd = '\''.$pw.'\'';
  55. }
  56. $this->User->recursive = -1;
  57. $this->User->updateAll(array('password'=>$newPwd), array('password !='=>$pw));
  58. $count = $this->User->getAffectedRows();
  59. $this->out($count.' pwds resetted - DONE');
  60. }
  61. function help() {
  62. $this->out('-- Hash and Reset all user passwords with Auth(Ext) Component --');
  63. }
  64. }