From 7ecf653a701bfa4115fa2cc5fa438c1a5c4dfbaf Mon Sep 17 00:00:00 2001 From: pips Date: Thu, 30 Nov 2017 16:00:14 +0100 Subject: [PATCH] Fix endless loop whe generating uppercase char w/o ambiguous (#15) fix #13 Also modify testGenerateAmbiguous, ambiguous characters come from the uppercase set, thus it required to enable $capitalize in order to get some ambiguous ones. --- src/PWGen.php | 4 ++-- tests/PWGen/PWGenTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PWGen.php b/src/PWGen.php index eb12e7d..1194d25 100644 --- a/src/PWGen.php +++ b/src/PWGen.php @@ -291,8 +291,8 @@ private function pw_phonemes() if ($this->pwgen_flags & self::PW_UPPERS) { if (($first || $flags & self::CONSONANT) && (self::my_rand(0, 9) < 2) && - ($this->pwgen_flags & self::PW_AMBIGUOUS) && - strpos(self::$pw_ambiguous, strtoupper($this->password[$c])) === false) { + (($this->pwgen_flags & self::PW_AMBIGUOUS) || + strpos(self::$pw_ambiguous, strtoupper($this->password[$c])) === false)) { $this->password[$c] = strtoupper($this->password[$c]); $feature_flags &= ~self::PW_UPPERS; } diff --git a/tests/PWGen/PWGenTest.php b/tests/PWGen/PWGenTest.php index a387615..437721c 100644 --- a/tests/PWGen/PWGenTest.php +++ b/tests/PWGen/PWGenTest.php @@ -113,7 +113,7 @@ public function testGenerateCapitalize() public function testGenerateAmbiguous() { - $pwgen = new PWGen(20, false, false, false, true); + $pwgen = new PWGen(20, false, false, true, true); $this->assertEquals(20, $pwgen->getLength()); $this->assertTrue($pwgen->hasAmbiguous());