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. * @author Mark Scherer
  8. * @license http://opensource.org/licenses/mit-license.php MIT
  9. */
  10. class PwdShell extends AppShell {
  11. /**
  12. * PwdShell::hash()
  13. *
  14. * @return void
  15. */
  16. public function hash() {
  17. $components = ['Tools.AuthExt', 'Auth'];
  18. $class = null;
  19. foreach ($components as $component) {
  20. if (App::import('Component', $component)) {
  21. $component .= 'Component';
  22. list($plugin, $class) = pluginSplit($component);
  23. break;
  24. }
  25. }
  26. if (!$class || !method_exists($class, 'password')) {
  27. return $this->error('No Auth Component found');
  28. }
  29. $this->out('Using: ' . $class);
  30. while (empty($pwToHash) || mb_strlen($pwToHash) < 2) {
  31. $pwToHash = $this->in('Password to Hash (2 characters at least)');
  32. }
  33. if ($authType = Configure::read('Passwordable.authType')) {
  34. list($plugin, $authType) = pluginSplit($authType, true);
  35. $className = $authType . 'PasswordHasher';
  36. App::uses($className, $plugin . 'Controller/Component/Auth');
  37. $passwordHasher = new $className();
  38. $pw = $passwordHasher->hash($pwToHash);
  39. } else {
  40. $class = new $class(new ComponentCollection());
  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. }