Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Passwort Generator
<?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