[PHP] Generate a random password

Dieser Beitrag ist auch verfügbar in: German

Hi,

because I need that from time to time and always looking again for a good function… here my memory aid. :-)

$pwZeichen = 'wertzupasdfghkyxcvbnmWERTZUPLKJHGFDSAYXCVBNM23456789';
srand ((double)microtime()*1000000);
for($i = 0; $i < 5; $i++) {
$passwort .= substr( $pwZeichen, (rand()%(strlen ($pwZeichen) ) ), 1);
}

In the variable $pwZeichen are all signs which can be used in the password. ‘srand’ starts the random generator (else the password would include always the same signs) ;-)
The ‘for’ loop set how long the password will be. Here 5 digits. You can change the value of course. And last but not least are the signs added to the variable $passwort.

That’s it :)

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *


*