Skip to content

Instantly share code, notes, and snippets.

@mikedugan
Created November 7, 2013 14:51
Show Gist options
  • Select an option

  • Save mikedugan/7355843 to your computer and use it in GitHub Desktop.

Select an option

Save mikedugan/7355843 to your computer and use it in GitHub Desktop.
password generator
<?php
function passStr($len, $set = "") {
$gen = "";
for($i=0;$i<$len;$i++) {
$set = str_shuffle($set);
$gen .= $set[0];
}
return $gen;
}
$passcode=passStr(8,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
echo $passcode;
?>
<?php
function passGenStr() {
// first we get all printable chars from ASCII table
$arr = range(chr(33), chr(126));
// Remove problematic chars
unset($arr[1], $arr[6], $arr[11], $arr[63]);
// Now lets generate strong password from these ascii chars
$pwd = implode('', array_rand(array_flip($arr) , 10));
return $pwd;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment