Create easily readable password in PHP


/ Published in: PHP
Save to your folder(s)

Now, it’s true that if we use this function to generate passwords, the passwords created will be less secure — this function can only create 285 (17 million) different five-character passwords whereas if I had included the missing characters this number would’ve been 365 (60 million). That’s a trade-off you’ll have to accept in return for fewer frustrated users having difficulty logging on to your site, which can be mitigated by forcing users to change their generated password to something chosen by them.


Copy this code and paste it in your HTML
  1. function GenerateRandomString($length) {
  2. $characters = array('2', '3', '4', '5', '6', '7', '8', '9',
  3. 'a', 'c', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'p',
  4. 'q', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
  5. $randomString = "";
  6. while(strlen($randomString) < $length) {
  7. $randomCharacterIndex = rand(0, count($characters));
  8. $randomString .= $characters[$randomCharacterIndex];
  9. }
  10. return $randomString;
  11. }

URL: http://www.sitepoint.com/blogs/2008/11/13/how-to-create-friendlier-random-passwords/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.