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

fris on 08/16/08


Tagged

password random String


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

kiarashM
luman


random password generator


Published in: PHP 


  1. <?
  2.  
  3. function random_password($max)
  4. {
  5. $val = '';
  6. $charset = "abcdefghijkmnpqrstuvwxyz0123456789";
  7. for ($i = 0; $i < $max; $i++)
  8. {
  9. $val .= $charset[mt_rand(0, strlen($charset) - 1)];
  10. }
  11.  
  12. return $val;
  13. }
  14.  
  15. ?>

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: Scooter on August 16, 2008

It would be good to also add uppercase letters, and possibly also special characters, for a stronger password.

Additionally, you may wish to check the password that it contains at least one of each kind (upper, lower, number, special) before returning it.

You need to login to post a comment.