Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,959 questions

51,901 answers

573 users

How to generate random password in PHP

2 Answers

0 votes
$password = substr(md5(microtime().rand(1, 100000)), 0, 6);

echo $password;

 
 
 
/*
run:
 
9f7caf
 
*/



answered May 9, 2014 by avibootz
edited Apr 14, 2024 by avibootz
0 votes
function generateRandomPassword($slen = 8) {
    $chars = "0123456789-=+{}[]:;#~.?/,\!$%^*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
      
    $len = strlen($chars);
      
    $randomString = '';
    for ($i = 0; $i < $slen; $i++) {
        $randomString .= $chars[rand(0, $len - 1)];
    }
    
    return $randomString;
}
   
$s = generateRandomPassword(6) . "\n"; 
echo $s;
 
$s = generateRandomPassword(12) . "\n"; 
echo $s;
   
   
   
   
   
/*
run:

%OJZWw
Ka$O1XIPj[;z
   
*/

 



answered Apr 14, 2024 by avibootz

Related questions

1 answer 182 views
1 answer 168 views
168 views asked Jul 19, 2016 by avibootz
1 answer 84 views
1 answer 85 views
1 answer 69 views
1 answer 71 views
3 answers 124 views
124 views asked Dec 22, 2024 by avibootz
...