[PHP] Generate a random password
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 :)
Hinterlasse einen Kommentar
An der Diskussion beteiligen?Hinterlasse uns deinen Kommentar!