pwd.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. class PwdShell extends Shell {
  3. var $tasks = array();
  4. //var $uses = array('User');
  5. var $Auth = null;
  6. function main() {
  7. $components = array('AuthExt', 'Auth');
  8. foreach ($components as $component) {
  9. if (App::import('Component', $component)) {
  10. $component .='Component';
  11. $this->Auth = new $component();
  12. break;
  13. }
  14. }
  15. if (!is_object($this->Auth)) {
  16. $this->out('No Auth Component found');
  17. die();
  18. }
  19. $this->out('Using: '.get_class($this->Auth));
  20. while (empty($pwToHash) || mb_strlen($pwToHash) < 2) {
  21. $pwToHash = $this->in(__('Password to Hash (2 characters at least)', true));
  22. }
  23. $pw = $this->Auth->password($pwToHash);
  24. $this->hr();
  25. echo $pw;
  26. }
  27. function hash() {
  28. if (!empty($this->args[0]) && in_array(strtolower($this->args[0]), hash_algos())) {
  29. $type = strtolower($this->args[0]);
  30. } else {
  31. # prompt for one
  32. $type = $this->in(__('Hash Type', true), array_combine(array_values(hash_algos()), array_values(hash_algos())), 'sha1');
  33. }
  34. $pwd = '123';
  35. $this->hr();
  36. echo hash($type, $pwd);
  37. }
  38. function compare() {
  39. $algos = hash_algos();
  40. $data = "hello";
  41. foreach ($algos as $v) {
  42. $res = hash($v, $data, false);
  43. $r = str_split($res, 50);
  44. printf("%-12s %3d %s\n", $v, strlen($res), array_shift($r));
  45. while (!empty($r)) {
  46. printf(" %s\n", array_shift($r));
  47. }
  48. }
  49. }
  50. function help() {
  51. $this->out('-- Hash Passwort with Auth(Ext) Component --');
  52. $this->out('-- cake pwd');
  53. $this->out('---- using the salt of the core.php (!)');
  54. $this->out('-- cake pwd hash [method]');
  55. $this->out('---- for custom hashing of pwd strings (method name optional)');
  56. $this->out('-- cake pwd compare');
  57. $this->out('---- to list all available methods and their lenghts');
  58. }
  59. }