Super Easy Random String Generator - Useful for Passwords


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

I needed a way to generate some random strings for passwords, a number of methods seemed a little over the top so below is my simplified version that does the trick. I have set it to use non-confusing characters, so no i's, l's, 0's but very easy to change.


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. /*
  4. * str_shuffle to generate a random series of characters based on those provided, uniqid added, then shuffled again.
  5. * substr will trim the output down to between 10 and 12 characters randomly.
  6. */
  7.  
  8. //Generate 10 Random Strings
  9. $i = 1;
  10. while($i <= 10){
  11. echo substr(str_shuffle(uniqid(str_shuffle("abcdefghjkmnpqrstwxyzABCDEFGHJKMNPQRSTWXYZ23456789"))), 0, rand(10,12))."<br/>";
  12. $i++;
  13. }
  14.  
  15. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.