Breaking News
Home / Web / PHP / PHP Snippets / How to generate random password in PHP?

How to generate random password in PHP?

Snippet

  1. # Random Password
  2. function random_password($maxlen) {
  3. $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  4.     srand((double)microtime() * 1000000);
  5.     $i = 0;
  6.     $pass = ;
  7.  
  8.     while ($i <=$maxlen) {
  9.     $num = rand() % 62;
  10.         $tmp = substr($chars,$num,1);
  11.         $pass = $pass.$tmp;
  12.         $i++;
  13.     }
  14. return$pass;
  15. }
[pb_builder]

Check Also

How to list files in a directory in PHP?

<?php if ($handle = opendir(‘/path/to/directory’)) {     echo "Directory handle: $handlen";     echo …

Advertisment ad adsense adlogger