PwdShell.php 1.5 KB

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