Jump to Content

bencarpenter.co.uk: Articles... Passwords

Buuf Graphics. Damn Mattahan's a good artist!

Simple password generator

The three passwords below have been generated at random from the mixed-case alphanumeric group of characters. Each 'class' of characters (uppercase, lowercase and numeric) have equal probability of occurring and the characters within each class also occur with equal probability. The default password length is 8 characters.

c4nPT48l        qa0N02wf        k8dDi876

Of course, this is easily extensible with symbols or any other range of characters. In fact, the more diverse the character set the better the password provided the use for it will accept non-alphanumeric characters. A future update to this page will include a selector for character sets and password length...

The PHP source code is provided here for the curious, or for those who would like to use this tool in their own projects.

<?php
function create_password($length = 8) {
  $options = array(
    0 => range('a', 'z'),
    1 => range('A', 'Z'),
    2 => range('0', '9')
  );
  
  for($i=0; $i<$length; $i++) {
    $idx = mt_rand(0, count($options)-1 );
    $pwd .= $options[$idx][ mt_rand(0,count($options[$idx])-1) ];
  }
  return $pwd;
}
?>
Last updated Monday, 5th May 2008 @ 19:48
Valid CSS! Valid XHTML 1.1!