In the last post, Generating Random Passwords 2 – Controlling the Character Pool , we were able to customize the character pool for passwords on the fly. Since we are talking about passwords for one piece of software to talk to another software, the character pool does not need to have characters that are on our keyboard.
So, let’s try extending our password generator to be able to generate untypable characters.
So first, let’s make the function that will have the pool of untypable characters in it. This function will go into RandomPassword.php
24 25 26 27 28 29 |
public static function generateRandomPasswordUntypable(int $length = 12) { $pool = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ■²ⁿ√·∙°≈÷⌡⌠≤≥±≡∩εφ∞δΩΘΦτµσΣπΓßα▀▐▌▄█┌┘╪╫╓╒╘╙╥╤╨←╬═╠╦╩╔╚╟╞┼─├┬┴└┐╛╜╝╗║╣╕╖╢╡┤│▓▒░»«¡¼½¬⌐¿ºªÑñúóíáƒ₧¥£¢ÜÖÿùûòöôÆæÉÅÄìîïèëêçåàäâéüÇ⌂'; return static::generateRandomPassword($length, $pool); } |
Those are some sweet untypable characters! I used an ASCII code sheet, the new characters are code points 128-255.
And now to call it, I will just add a flag “–u” to the application.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
protected function configure() { $this->setName("gen") ->setDescription("Generates a randomized password") ->addArgument('Password Length', InputArgument::REQUIRED, 'The length of the resulting password') ->addArgument('Character Set', InputArgument::OPTIONAL, 'The set of characters to use') ->addOption('u', null, InputOption::VALUE_NONE, 'Use untypable characters') ; } protected function execute(InputInterface $input, OutputInterface $output) { $RP = new RandomPassword(); if($input->getArgument('Character Set')){ $pwd = $RP::generateRandomPassword($input->getArgument('Password Length'), $input->getArgument('Character Set')); }elseif($input->getOption('u')){ $pwd = $RP::generateRandomPasswordUntypable($input->getArgument('Password Length')); } else{ $pwd = $RP::generateRandomPassword($input->getArgument('Password Length')); } $output->writeln($pwd); } |
That is all we need to be able to generate random passwords with the extra untypable characters.
1 2 3 |
$ php pwdrnd gen 32 --u %öEΓöƒöyÇ2?╡Γ&£Γ¿.ò├ò£G╖├,>╬0º5= |
Would you look at that? I do not have most of those characters on my keyboard. I’d be willing to bet that someone trying to crack this password may not try some of these characters.
Note: In some consoles, this will happen.
1 2 3 |
$ php pwdrnd gen 32 --u �6������$�-�²�m�����G�k���j |
I have no idea, yet, as to what is causing this. I get the invalid character marker with Windows 8.1 and Ubuntu 17.04, but Windows 7 is fine. It may have something to do with the PHP version, I’m running 7.0 on Windows 7, and 7.1 on both Windows 8.1 and Ubuntu. More experimentation is needed!
The repository for this post can be found on GitHub here .
The repository for this post can be found on GitLab here .
The repository for this post can be found on Lupe Code’s GitLab mirror here .