fork download
  1. <?php
  2. class IO
  3. {
  4. protected $handle, $storage = array();
  5.  
  6. public function write( $string )
  7. {
  8. echo $string;
  9. }
  10.  
  11. public function output( $reference, $request )
  12. {
  13. $this->write($request);
  14. $this->handle = fopen ("php://stdin","r");
  15. $this->storage[$reference] = fgets($this->handle);
  16. }
  17.  
  18. public function input( $reference )
  19. {
  20. return $this->storage[$reference];
  21. }
  22. }
  23.  
  24.  
  25. class App
  26. {
  27. public function __construct( IO $terminal )
  28. {
  29. $this->terminal = $terminal;
  30. $this->welcome();
  31. $this->main();
  32. }
  33.  
  34. protected function generate( $chars, $starter )
  35. {
  36. $password = "";
  37.  
  38. while(strlen($password) < $chars)
  39. {
  40. $password .= crypt ( rand(0, 900).$starter.rand(0, 900), rand(0, 900).$starter.rand(0, 900) );
  41. }
  42.  
  43. return substr($password, 0, intval($chars));
  44.  
  45. }
  46.  
  47. protected function welcome()
  48. {
  49. $this->terminal->write("
  50. == PHP Password Generator v1.0 ===============
  51. ========== By Jeremy Feinstein ===============
  52. ");
  53. }
  54.  
  55. protected function main()
  56. {
  57. $this->terminal->output( "chars", "\n Number of password characters? " );
  58. $this->terminal->output( "starter", " Give me something random: " );
  59.  
  60. $chars = $this->terminal->input( "chars" );
  61. $starter = $this->terminal->input( "starter" );
  62. $password = $this->generate( $chars, $starter );
  63.  
  64. $this->terminal->write( "\n Ahh, the fresh smell of a new password: " . $password . "\n\n");
  65. }
  66. }
  67.  
  68. $terminal = new IO();
  69. new App($terminal);
  70. ?>
Success #stdin #stdout 0.01s 20568KB
stdin
20
@#AskUbuntu!(#$)
stdout
== PHP Password Generator v1.0 ===============
========== By Jeremy Feinstein ===============

 Number of password characters?  Give me something random: 
 Ahh, the fresh smell of a new password: 71LQIYurt0psk25Zkjop