PwdShell.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 $tasks = array();
  14. //public $uses = array('User');
  15. public $Auth = null;
  16. public function hash() {
  17. $components = array('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. $this->out(__('No Auth Component found'));
  28. die();
  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. $pw = $class::password($pwToHash);
  35. $this->hr();
  36. echo $pw;
  37. }
  38. public function help() {
  39. $this->out('-- Hash Passwort with Auth(Ext) Component --');
  40. $this->out('-- cake Tools.Pwd hash');
  41. $this->out('---- using the salt of the core.php (!)');
  42. }
  43. }