$all_of_them = array (
A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Z,
a,b,c,d,e,f,g,h,i,j,k,m,n,o,p,q,r,s,t,u,v,w,x,y,z,
2,3,4,5,6,7,8,9);
function genpassword($length=8){
global $all_of_them;
srand(time());
$num_all_of_them = count($all_of_them);
for($i = 0; $i < $length; $i++){
srand ((double) microtime() * 1000000);
$suggestpass .= $all_of_them[rand(0, $num_all_of_them - 1)];
}
return substr($suggestpass, 0, $length);
}
// Set some defaults:
$u = ($u ? $u : "karltoffel");
$_REQUEST['pswlen'] = $_REQUEST['pswlen'] > 0 ? $_REQUEST['pswlen'] : 10;
print "
\n";
print "\n";
$_REQUEST['p'] = ($_REQUEST['wantedpsw'] ? trim($_REQUEST['wantedpsw']) : genpassword($_REQUEST['pswlen']));
if (strlen($_REQUEST['p'])<3) {
print "A password only ". strlen($_REQUEST['p']) ." character". (strlen($_REQUEST['p'])!=1 ? 's' : '') ." long? Quite ridiculous, isn't it?\n\n";
}
print "To login as «" . $_REQUEST['u'] . "» with ". ( $_REQUEST['p'] ? 'your ' : 'the suggested ') . "password «" . $_REQUEST['p'] . "» you should add the line\n";
print "" . $_REQUEST['u'] . ":". crypt($_REQUEST['p'],substr($u,0,2)) ."
";
print "to your .htpasswd file.\n";
print "\n";
print "A sample .htaccess file might look likes this:\n";
print "";
print "AuthUserFile /var/www/karltoffel.de/htdocs/.htpasswd\n";
print "AuthName \"This is a protected page\"\n";
print "AuthType Basic\n";
print "Require valid-user\n";
print "\n";
print "<FilesMatch .ht*>\n";
print " Order allow,deny\n";
print " Allow from none\n";
print " Deny from all\n";
print "</FilesMatch>\n";
print "
";
print "See Apache docs for details: require, mod_access, FilesMatch, htaccess-files etc.\n";
print "\n\n";
print "A note on password generation:\n";
print "Passwords are made from: " . join (",",$all_of_them) . "\n";
print "For obvious reason the letters/numbers O0l1 will not be used.\n";
?>
View source: fancy or plain