Commit f649b42d authored by Dries's avatar Dries
Browse files

- Patch #44767 by jvandyk: small (code) improvements

parent 84beb258
...@@ -285,14 +285,11 @@ function user_password($length = 10) { ...@@ -285,14 +285,11 @@ function user_password($length = 10) {
// This variable contains the list of allowable characters for the // This variable contains the list of allowable characters for the
// password. Note that the number 0 and the letter 'O' have been // password. Note that the number 0 and the letter 'O' have been
// removed to avoid confusion between the two. The same is true // removed to avoid confusion between the two. The same is true
// of 'I' and 1. // of 'I', 1, and l.
$allowable_characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'; $allowable_characters = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
// We see how many characters are in the allowable list: // Zero-based count of characters in the allowable list:
$len = strlen($allowable_characters); $len = strlen($allowable_characters) - 1;
// Seed the random number generator with the microtime stamp.
mt_srand((double)microtime() * 1000000);
// Declare the password as a blank string. // Declare the password as a blank string.
$pass = ''; $pass = '';
...@@ -302,7 +299,7 @@ function user_password($length = 10) { ...@@ -302,7 +299,7 @@ function user_password($length = 10) {
// Each iteration, pick a random character from the // Each iteration, pick a random character from the
// allowable string and append it to the password: // allowable string and append it to the password:
$pass .= $allowable_characters[mt_rand(0, $len - 1)]; $pass .= $allowable_characters[mt_rand(0, $len)];
} }
return $pass; return $pass;
......
...@@ -285,14 +285,11 @@ function user_password($length = 10) { ...@@ -285,14 +285,11 @@ function user_password($length = 10) {
// This variable contains the list of allowable characters for the // This variable contains the list of allowable characters for the
// password. Note that the number 0 and the letter 'O' have been // password. Note that the number 0 and the letter 'O' have been
// removed to avoid confusion between the two. The same is true // removed to avoid confusion between the two. The same is true
// of 'I' and 1. // of 'I', 1, and l.
$allowable_characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'; $allowable_characters = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
// We see how many characters are in the allowable list: // Zero-based count of characters in the allowable list:
$len = strlen($allowable_characters); $len = strlen($allowable_characters) - 1;
// Seed the random number generator with the microtime stamp.
mt_srand((double)microtime() * 1000000);
// Declare the password as a blank string. // Declare the password as a blank string.
$pass = ''; $pass = '';
...@@ -302,7 +299,7 @@ function user_password($length = 10) { ...@@ -302,7 +299,7 @@ function user_password($length = 10) {
// Each iteration, pick a random character from the // Each iteration, pick a random character from the
// allowable string and append it to the password: // allowable string and append it to the password:
$pass .= $allowable_characters[mt_rand(0, $len - 1)]; $pass .= $allowable_characters[mt_rand(0, $len)];
} }
return $pass; return $pass;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment