From f649b42d9c3d654da63d38be28ba0eda1aa24ef0 Mon Sep 17 00:00:00 2001 From: Dries Buytaert <dries@buytaert.net> Date: Sun, 15 Jan 2006 16:57:56 +0000 Subject: [PATCH] - Patch #44767 by jvandyk: small (code) improvements --- modules/user.module | 13 +++++-------- modules/user/user.module | 13 +++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/modules/user.module b/modules/user.module index e9b911587eda..981e902bf278 100644 --- a/modules/user.module +++ b/modules/user.module @@ -285,14 +285,11 @@ function user_password($length = 10) { // This variable contains the list of allowable characters for the // password. Note that the number 0 and the letter 'O' have been // removed to avoid confusion between the two. The same is true - // of 'I' and 1. - $allowable_characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'; + // of 'I', 1, and l. + $allowable_characters = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'; - // We see how many characters are in the allowable list: - $len = strlen($allowable_characters); - - // Seed the random number generator with the microtime stamp. - mt_srand((double)microtime() * 1000000); + // Zero-based count of characters in the allowable list: + $len = strlen($allowable_characters) - 1; // Declare the password as a blank string. $pass = ''; @@ -302,7 +299,7 @@ function user_password($length = 10) { // Each iteration, pick a random character from the // 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; diff --git a/modules/user/user.module b/modules/user/user.module index e9b911587eda..981e902bf278 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -285,14 +285,11 @@ function user_password($length = 10) { // This variable contains the list of allowable characters for the // password. Note that the number 0 and the letter 'O' have been // removed to avoid confusion between the two. The same is true - // of 'I' and 1. - $allowable_characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'; + // of 'I', 1, and l. + $allowable_characters = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'; - // We see how many characters are in the allowable list: - $len = strlen($allowable_characters); - - // Seed the random number generator with the microtime stamp. - mt_srand((double)microtime() * 1000000); + // Zero-based count of characters in the allowable list: + $len = strlen($allowable_characters) - 1; // Declare the password as a blank string. $pass = ''; @@ -302,7 +299,7 @@ function user_password($length = 10) { // Each iteration, pick a random character from the // 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; -- GitLab