To administer your WestHost account, please enter your
Domain Name or Server Manager Username.

WestHost
  • getCenter

    By subrahmanyam, submitted on 03/15/2011
  • Image Compress & Resize

    By Arivazhagan, submitted on 03/14/2011
  • AmPM

    By Ali A, submitted on 03/13/2011
  • mysqlToHuman

    By Ali a, submitted on 03/13/2011
  • time_ago

    By Bui Hoang Hai, submitted on 03/11/2011

VIEW MORE ENTRIES


Memorizable password generator

Jan Martinek, submitted on 03/07/2011

Simple 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).

Average rating 1.5253 / 99 Votes

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);
?>
Share |

blog comments powered by Disqus
 
 
Follow WestHost: Twitter Facebook Copyright © 1998–2010, WestHost. All rights reserved.  |  WestHost / Believe in Better Hosting.
Chat Live Now