PwdShell.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. App::uses('AppShell', 'Console/Command');
  3. App::uses('ComponentCollection', 'Controller');
  4. /**
  5. * password hashing and output
  6. *
  7. * @cakephp 2.x
  8. * @author Mark Scherer
  9. * @license MIT
  10. * 2011-11-05 ms
  11. */
  12. class PwdShell extends AppShell {
  13. public $Auth = null;
  14. /**
  15. * PwdShell::hash()
  16. *
  17. * @return void
  18. */
  19. public function hash() {
  20. $components = array('Tools.AuthExt', 'Auth');
  21. $class = null;
  22. foreach ($components as $component) {
  23. if (App::import('Component', $component)) {
  24. $component .='Component';
  25. list($plugin, $class) = pluginSplit($component);
  26. break;
  27. }
  28. }
  29. if (!$class || !method_exists($class, 'password')) {
  30. $this->out(__('No Auth Component found'));
  31. die();
  32. }
  33. $this->out('Using: '.$class);
  34. while (empty($pwToHash) || mb_strlen($pwToHash) < 2) {
  35. $pwToHash = $this->in(__('Password to Hash (2 characters at least)'));
  36. }
  37. $pw = $class::password($pwToHash);
  38. $this->hr();
  39. echo $pw;
  40. }
  41. /**
  42. * PwdShell::help()
  43. *
  44. * @return void
  45. */
  46. public function help() {
  47. $this->out('-- Hash Passwort with Auth(Ext) Component --');
  48. $this->out('-- cake Tools.Pwd hash');
  49. $this->out('---- using the salt of the core.php (!)');
  50. }
  51. }