Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: Mateusz
- * Date: 2018-09-07
- * Time: 15:09
- */
- class GeneratePassword
- {
- public $upperChars;
- public $lowerChars;
- public $numbers;
- public function __construct(int $upperChars, int $lowerChars, int $numbers)
- {
- $this->upperChars = $upperChars;
- $this->lowerChars = $lowerChars;
- $this->numbers = $numbers;
- }
- /**
- * @return int
- */
- public function getUpperChars(): int
- {
- return $this->upperChars;
- }
- /**
- * @param int $upperChars
- * @return GeneratePassword
- */
- public function setUpperChars(int $upperChars): GeneratePassword
- {
- $this->upperChars = $upperChars;
- return $this;
- }
- /**
- * @return int
- */
- public function getLowerChars(): int
- {
- return $this->lowerChars;
- }
- /**
- * @param int $lowerChars
- * @return GeneratePassword
- */
- public function setLowerChars(int $lowerChars): GeneratePassword
- {
- $this->lowerChars = $lowerChars;
- return $this;
- }
- /**
- * @return int
- */
- public function getNumbers(): int
- {
- return $this->numbers;
- }
- /**
- * @param int $numbers
- * @return GeneratePassword
- */
- public function setNumbers(int $numbers): GeneratePassword
- {
- $this->numbers = $numbers;
- return $this;
- }
- public function initializePassword(int $min, int $max, int $loops, string $type): string
- {
- $password = '';
- for($i = 0; $i<$loops; $i++ ) {
- switch($type) {
- case 'char':
- $password = $password.chr(rand($min, $max));
- break;
- case 'number':
- $password = $password.ord(rand($min, $max));
- break;
- }
- }
- return $password;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement