PwdShell.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. */
  11. class PwdShell extends AppShell {
  12. public $Auth = null;
  13. /**
  14. * PwdShell::hash()
  15. *
  16. * @return void
  17. */
  18. public function hash() {
  19. $components = array('Tools.AuthExt', 'Auth');
  20. $class = null;
  21. foreach ($components as $component) {
  22. if (App::import('Component', $component)) {
  23. $component .= 'Component';
  24. list($plugin, $class) = pluginSplit($component);
  25. break;
  26. }
  27. }
  28. if (!$class || !method_exists($class, 'password')) {
  29. return $this->error(__('No Auth Component found'));
  30. }
  31. $this->out('Using: '.$class);
  32. while (empty($pwToHash) || mb_strlen($pwToHash) < 2) {
  33. $pwToHash = $this->in(__('Password to Hash (2 characters at least)'));
  34. }
  35. $pw = $class::password($pwToHash);
  36. $this->hr();
  37. echo $pw;
  38. }
  39. /**
  40. * PwdShell::help()
  41. *
  42. * @return void
  43. */
  44. public function help() {
  45. $this->out('-- Hash Passwort with Auth(Ext) Component --');
  46. $this->out('-- cake Tools.Pwd hash');
  47. $this->out('---- using the salt of the core.php (!)');
  48. }
  49. }