Memorizable password generator
Jan Martinek, submitted on 03/07/2011Simple password generator, optional parameters to set length of password, its memorizability (by trying to create pseudo-syllables), mixed lettercase and option to force presence of numbers in the result (when FALSE, numbers also *can* be present in the result).
Tags: memorizable passwords password password generator
<?php /** * Creates and returns password * @param int password string length * @param bool create memorizable passwords (= do not create strings with two neighbouring consonants) * @param bool mixed case * @param bool force presence of numbers in generated passwords * @return string password */ function password($length = 8, $memorizable = TRUE, $mixedCase = FALSE, $forceNumber = FALSE) { $password; //doublets o/0 and l/1 missing because of their similarity $characters = 'abcdefghijkmnpqrstuvxyz23456789-'; $numbers = '23456789'; $vowels = 'aeiouy'; //numbers included because in memorizable pw's //they act as whole words + they improve password strength $consonants = 'bcdfghjkmnpqrstvxz23456789'; //drives occurences of vowels and consonants in memorizable passwords $meaninglessCounter = 1; while (mb_strlen($password) < $length) { if ($memorizable) //chooses from separate $numbers a $vowels and $consonants { if ($meaninglessCounter%2 == 0) { $char = $vowels[rand(0, strlen($vowels)-1)]; // pseudo-probably every third case skips to another vowel if (round(rand(0,2)%3 == 0)) $meaninglessCounter++; } else { $char = $consonants[rand(0, strlen($consonants)-1)]; } $meaninglessCounter++; } else { // chooses from a heap of $characters $char = $characters[rand(0, strlen($characters)-1)]; } if ($mixedCase) { // pseudo-probably every third char is capital letter if (round(rand(0,2)%3 == 0)) $char = strtoupper($char); } $password .= $char; } if ($forceNumber) { $password = strtr($password, array($password[rand(0, strlen($password)-1)] => $numbers[rand(0, strlen($numbers)-1)])); } return $password; } /* DEMO TIME */ echo password() . "\n"; /* echoes 10 letters password w/ mixed lower- and uppercase characters, ensures there is a number in the password */ echo password(10, TRUE, TRUE, TRUE); ?>
blog comments powered by Disqus
CDP
Continuous Data Protection takes a snapshot of your site every six hours and allows you to restore as many or as few files as you wish; all done without talking to anyone but your keyboard. Add it in the order form.
Hosting Solutions
Web HostingReseller Hosting
Cloud Servers
Dedicated Servers
Domain Registration
Register a DomainDomain Hosting
Information Center
About WestHostContact Us
Media Center
Forum
Blog
Careers
Affiliates
Data Center
Terms & Policies
Site Map