From df7d22ced3535ad305aba3cfc30b0e4074b0c99a Mon Sep 17 00:00:00 2001 From: Michael Schmitt Date: Wed, 24 Feb 2016 12:26:48 +0100 Subject: [PATCH] Dissallow certain special chars - some PHP Projects do not support special chars for Passwords. Wordpress for Example does not allow the Backslash \ - so I wrote the method blacklistSymbol --- PWGen.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/PWGen.php b/PWGen.php index 88d1626..4585d27 100644 --- a/PWGen.php +++ b/PWGen.php @@ -408,6 +408,25 @@ private static function __static() { } } + /** + * Disallow certain special chars + * @param array $symbols + */ + public function blacklistSymbol(array $symbols ) + { + foreach ($symbols as $symbol) { + if (!preg_match('/' . preg_quote($symbol) . '/', self::$pw_symbols)) { + return; + } + } + $symbolArray = str_split(self::$pw_symbols); + foreach ($symbols as $symbol) { + $index =array_search($symbol, $symbolArray); + unset($symbolArray[$index]); + } + self::$pw_symbols = implode('', $symbolArray); + } + /** * Returns the last generated password. If there is none, a new one will be generated. */