Password Encryption Tool
0) {
$newchar = mt_rand($start, $end);
if (!strrpos($valid_chars, $newchar))
continue; // skip holes
$newpass .= sprintf("%c", $newchar);
$length--;
}
return $newpass;
}
/** PHP5 deprecated old-style globals if !(bool)ini_get('register_long_arrays').
* See Bug #1180115
* We want to work with those old ones instead of the new superglobals,
* for easier coding.
*/
foreach (array('SERVER', 'GET', 'POST', 'ENV') as $k) {
if (!isset($GLOBALS['HTTP_' . $k . '_VARS']) and isset($GLOBALS['_' . $k]))
$GLOBALS['HTTP_' . $k . '_VARS'] =& $GLOBALS['_' . $k];
}
unset($k);
$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;
$posted['password2'] = $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";
} elseif ($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 = $_SERVER['REQUEST_URI'];
?>