Posted By

nsbucky on 01/12/11


Tagged

php password random


Versions (?)

PHP Password Generator


 / Published in: PHP
 

Function to simply generate a random password.

  1. function generatePassword($length=8)
  2. {
  3. $chars = array_merge(range(0,9),
  4. range('a','z'),
  5. range('A','Z'),
  6. array('!','@','$','%','^','&','*')); shuffle($chars);
  7. $password = '';
  8. for($i=0; $i<8; $i++) {
  9. $password .= $chars[$i];
  10. }
  11. return $password;
  12. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: ohryan on January 21, 2011

Shuffle is not random, as such this is probably not the great method for generating a password: http://www.php.net/manual/en/function.shuffle.php#41593

You need to login to post a comment.