Advertisement
Guest User

Untitled

a guest
Sep 7th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Mateusz
  5. * Date: 2018-09-07
  6. * Time: 15:09
  7. */
  8.  
  9. class GeneratePassword
  10. {
  11. public $upperChars;
  12. public $lowerChars;
  13. public $numbers;
  14.  
  15.  
  16. public function __construct(int $upperChars, int $lowerChars, int $numbers)
  17. {
  18. $this->upperChars = $upperChars;
  19. $this->lowerChars = $lowerChars;
  20. $this->numbers = $numbers;
  21. }
  22.  
  23. /**
  24. * @return int
  25. */
  26. public function getUpperChars(): int
  27. {
  28. return $this->upperChars;
  29. }
  30.  
  31. /**
  32. * @param int $upperChars
  33. * @return GeneratePassword
  34. */
  35. public function setUpperChars(int $upperChars): GeneratePassword
  36. {
  37. $this->upperChars = $upperChars;
  38. return $this;
  39. }
  40.  
  41. /**
  42. * @return int
  43. */
  44. public function getLowerChars(): int
  45. {
  46. return $this->lowerChars;
  47. }
  48.  
  49. /**
  50. * @param int $lowerChars
  51. * @return GeneratePassword
  52. */
  53. public function setLowerChars(int $lowerChars): GeneratePassword
  54. {
  55. $this->lowerChars = $lowerChars;
  56. return $this;
  57. }
  58.  
  59. /**
  60. * @return int
  61. */
  62. public function getNumbers(): int
  63. {
  64. return $this->numbers;
  65. }
  66.  
  67. /**
  68. * @param int $numbers
  69. * @return GeneratePassword
  70. */
  71. public function setNumbers(int $numbers): GeneratePassword
  72. {
  73. $this->numbers = $numbers;
  74. return $this;
  75. }
  76.  
  77. public function initializePassword(int $min, int $max, int $loops, string $type): string
  78. {
  79. $password = '';
  80. for($i = 0; $i<$loops; $i++ ) {
  81. switch($type) {
  82. case 'char':
  83. $password = $password.chr(rand($min, $max));
  84. break;
  85. case 'number':
  86. $password = $password.ord(rand($min, $max));
  87. break;
  88. }
  89. }
  90.  
  91. return $password;
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement