PwdShell.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. return $this->error(__('No Auth Component found'));
  31. }
  32. $this->out('Using: '.$class);
  33. while (empty($pwToHash) || mb_strlen($pwToHash) < 2) {
  34. $pwToHash = $this->in(__('Password to Hash (2 characters at least)'));
  35. }
  36. $pw = $class::password($pwToHash);
  37. $this->hr();
  38. echo $pw;
  39. }
  40. /**
  41. * PwdShell::help()
  42. *
  43. * @return void
  44. */
  45. public function help() {
  46. $this->out('-- Hash Passwort with Auth(Ext) Component --');
  47. $this->out('-- cake Tools.Pwd hash');
  48. $this->out('---- using the salt of the core.php (!)');
  49. }
  50. }