\n", 'iso-8859-1'); ?>
Password Encryption Tool
Password Encryption Tool
0.1)
$seed = (double) $usec * $sec;
else // once in a while use the combined LCG entropy
$seed = (double) 1000000 * substr(uniqid("", true), 13);
}
if (function_exists('mt_srand')) {
mt_srand($seed); // mersenne twister
} else {
srand($seed);
}
$wascalled = TRUE;
}
}
function rand_ascii($length = 1) {
better_srand();
$s = "";
for ($i = 1; $i <= $length; $i++) {
// return only typeable 7 bit ascii, avoid quotes
if (function_exists('mt_rand'))
// the usually bad glibc srand()
$s .= chr(mt_rand(40, 126));
else
$s .= chr(rand(40, 126));
}
return $s;
}
////
// Function to create better user passwords (much larger keyspace),
// suitable for user passwords.
// Sequence of random ASCII numbers, letters and some special chars.
// Note: There exist other algorithms for easy-to-remember passwords.
function random_good_password ($minlength = 5, $maxlength = 8) {
$newpass = '';
// assume ASCII ordering (not valid on EBCDIC systems!)
$valid_chars = "!#%&+-.0123456789=@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
$start = ord($valid_chars);
$end = ord(substr($valid_chars, -1));
better_srand();
if (function_exists('mt_rand')) // mersenne twister
$length = mt_rand($minlength, $maxlength);
else // the usually bad glibc rand()
$length = rand($minlength, $maxlength);
while ($length > 0) {
if (function_exists('mt_rand'))
$newchar = mt_rand($start, $end);
else
$newchar = rand($start, $end);
if (! strrpos($valid_chars, $newchar) )
continue; // skip holes
$newpass .= sprintf("%c", $newchar);
$length--;
}
return $newpass;
}
$posted = $GLOBALS['HTTP_POST_VARS'];
if (!empty($posted['create'])) {
$new_password = random_good_password();
echo "The newly created random password is:
\n
\n",
htmlentities($new_password),"
\n";
$posted['password'] = $new_password;
}
if (($posted['password'] != "")
&& ($posted['password'] == $posted['password2'])) {
$password = $posted['password'];
/**
* http://www.php.net/manual/en/function.crypt.php
*/
// Use the maximum salt length the system can handle.
$salt_length = max(CRYPT_SALT_LENGTH,
2 * CRYPT_STD_DES,
9 * CRYPT_EXT_DES,
12 * CRYPT_MD5,
16 * CRYPT_BLOWFISH);
// Generate the encrypted password.
$encrypted_password = crypt($password, rand_ascii($salt_length));
$debug = $HTTP_GET_VARS['debug'];
if ($debug)
echo "The password was encrypted using a salt length of: $salt_length
\n";
echo "The encrypted password is:
\n
\n",
htmlentities($encrypted_password),"
\n";
echo "
\n";
}
else if ($posted['password'] != "") {
echo "The passwords did not match. Please try again.
\n";
}
if (empty($REQUEST_URI))
$REQUEST_URI = $HTTP_ENV_VARS['REQUEST_URI'];
if (empty($REQUEST_URI))
$REQUEST_URI = $HTTP_SERVER_VARS['REQUEST_URI'];
?>