your password: na\-6qlhC#
genrated in 0.00021505355834961 sec
Copy the sourcecode and run it on you own server, if u want to!
<?php
$time = microtime(true);
define("CAPITAL", 1);
define("LOWER", 2);
define("NUM", 4);
define("SPECIAL", 8);
## set length and type of key ##
#length of the key
$length = 10;
#types of chars that may be included
$include = NUM | CAPITAL | LOWER | SPECIAL;
#types of chars that have to be included
$mustInclude = NUM | CAPITAL | LOWER | SPECIAL;
#setting vars
$ranges = array();
$ranges[CAPITAL] = array("from" => 65, "to" => 90);
$ranges[LOWER] = array("from" => 97, "to" => 122);
$ranges[NUM] = array("from" => 48, "to" => 57);
# generating key
$key = "";
while(strlen($key) < $length) {
$c = rand(33, 125);
$t = type($c);
if( !includes($include, $t) ||
countTypes($mustInclude) > 0 &&
$length-strlen($key) == countTypes($mustInclude) &&
!includes($mustInclude, $t))
continue;
$key .= chr($c);
if(includes($mustInclude, $t))
$mustInclude -= $t;
}
echo '<html>
<head>
<title>PW-Generator</title>
</head>
<body>
<div>
<p><strong>your password: ' . htmlspecialchars($key) . '</strong></p>
<p>genrated in ' . (microtime(true) - $time) . ' sec</p>
<p>Copy the sourcecode and run it on you own server, if u want to!</p>
<pre>' . htmlspecialchars(file_get_contents(__FILE__)) . '</pre>
</div>
</body>
</html>';
#checks whether a type is in types
function includes($types, $type) {
return ($types & $type) == $type;
}
#gets type from charCode
function type($c) {
global $ranges;
foreach($ranges as $type => $range) {
if($c >= $range["from"] && $c <= $range["to"]) {
return $type;
}
}
return SPECIAL;
}
#counts types in given types
function countTypes($types) {
global $ranges;
$n = 0;
foreach($ranges as $type => $range) {
if(includes($types, $type)) $n++;
}
return $n;
}
?>