We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

tylerhall on 08/28/07


Tagged

php textmate password


Versions (?)


Who likes this?

13 people have marked this snippet as a favorite

depmed
neuroasis
hudge
pagetoscreen
bioascii
leitmotiv
digitalifer
romanos
pixelhandler
davidhorn
grn
section31
sumandahal


Generate a Unambiguous Random Password


Published in: PHP 


This function generates a random password of a specified length in lower or mixed case letters and numbers. Ambiguous characters, such as I, L, 1, 0, and O, are left out so the user can easily read the password.

  1. function random_password($len = 7, $mixed_case = false)
  2. {
  3. $a = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789";
  4. if(!$mixed_case) $a = strtolower($a)
  5. $out = "";
  6. for($i = 0; $i < $len; $i++)
  7. $out .= $a[rand(0, strlen($a))];
  8. return $out;
  9. }

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: koncept on July 9, 2008

apparently mt_rand() is up to 4x faster

You need to login to post a comment.