From 3169be68380ec14af42880ff7f5f6586a9ab52f6 Mon Sep 17 00:00:00 2001 From: rurban Date: Sun, 8 Sep 2002 18:34:35 +0000 Subject: [PATCH] unix eol git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@2322 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- passencrypt.php | 286 ++++++++++++++++++++++++------------------------ 1 file changed, 143 insertions(+), 143 deletions(-) diff --git a/passencrypt.php b/passencrypt.php index 0ea840ae3..47396594b 100644 --- a/passencrypt.php +++ b/passencrypt.php @@ -1,143 +1,143 @@ -\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 created new random password is:
\n
   \n",htmlentities($new_password),"

\n"; - $posted['password'] = $new_password; -} - -if ($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"; -} -if (empty($REQUEST_URI)) - $REQUEST_URI = $HTTP_ENV_VARS['REQUEST_URI']; -if (empty($REQUEST_URI)) - $REQUEST_URI = $HTTP_SERVER_VARS['REQUEST_URI']; -?> - -
-
Password -Enter a password to encrypt: -
- -
Create -Create new random password: -
-
- - +\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 created new random password is:
\n
   \n",htmlentities($new_password),"

\n"; + $posted['password'] = $new_password; +} + +if ($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"; +} +if (empty($REQUEST_URI)) + $REQUEST_URI = $HTTP_ENV_VARS['REQUEST_URI']; +if (empty($REQUEST_URI)) + $REQUEST_URI = $HTTP_SERVER_VARS['REQUEST_URI']; +?> + +
+
Password +Enter a password to encrypt: +
+ +
Create +Create new random password: +
+
+ + -- 2.45.0