Created
January 26, 2019 18:54
-
-
Save radarin/d7681a3e5f10653c3005fd957d641cd5 to your computer and use it in GitHub Desktop.
Passwort Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Quelle: SnowCrash | |
// Funktion | |
function generatePW($length=8) | |
{ | |
// Zu verwendende Zeichen definieren | |
$dummy = array_merge(range('0', '9'), range('a', 'z'), range('A', 'Z'), array('#','&','@','$','_','%','?','+')); | |
// Array zufaellig fuellen | |
mt_srand((double)microtime()*1000000); | |
for ($i = 1; $i <= (count($dummy)*2); $i++) | |
{ | |
$swap = mt_rand(0,count($dummy)-1); | |
$tmp = $dummy[$swap]; | |
$dummy[$swap] = $dummy[0]; | |
$dummy[0] = $tmp; | |
} | |
// get password | |
return substr(implode('',$dummy),0,$length); | |
} | |
// Passwort anzeigen | |
echo generatePW(10); // Die Zahl in der Klammer definiert die Laenge des Passwortes | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment