Snippet : Generate Random Password

This snippet helps you to Generate Random Password

Function

  1. <?php 
  2. function Generate_Random($len, $set = "") {
  3. $generate = "";
  4. for($i=0;$i<$len;$i++) {
  5. $set = str_shuffle($set);
  6. $generate .= $set[0];
  7. }
  8. return $generate;
  9. }
  10. ?>
Usage of function

  1.  $Password=Generate_Random(10,'1234567890qwertyuiopasdfghjklzxcvbnm');
  2.  echo $Password;
In the first line inside the brackets you have to put how many characters to be generated(10) after that you need to add the characters that to be randomly generated(1234567890qwertyuiopasdfghjklzxcvbnm).

Recently I wrote something like this, you can view that article from this link.

Post a Comment

Note: Only a member of this blog may post a comment.