PwdShell.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. $pw = $class->password($pwToHash);
  42. }
  43. $this->hr();
  44. $this->out($pw);
  45. }
  46. /**
  47. * PwdShell::help()
  48. *
  49. * @return void
  50. */
  51. public function help() {
  52. $this->out('-- Hash Passwort with Auth(Ext) Component --');
  53. $this->out('-- cake Tools.Pwd hash');
  54. $this->out('---- using the salt of the core.php (!)');
  55. }
  56. }