From a4c6fc121fbf12568d5a1873a1e308190ea9e80f Mon Sep 17 00:00:00 2001 From: wbond Date: Sat, 13 Sep 2008 13:53:01 +0000 Subject: [PATCH] BackwardsCompatibilityBreak - fCryptography::generateRandomString() was renamed to fCryptography::randomString() --- classes/fCryptography.php | 118 +++++++++++++++++++------------------- classes/fORMColumn.php | 4 +- 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/classes/fCryptography.php b/classes/fCryptography.php index be31a42c..c4ea315c 100644 --- a/classes/fCryptography.php +++ b/classes/fCryptography.php @@ -33,64 +33,6 @@ static public function checkPasswordHash($password, $hash) } - /** - * Returns a random string of the type and length specified - * - * @param integer $length The length of string to return - * @param string $type The type of string to return, can be 'alphanumeric', 'alpha', 'numeric', or 'hexadecimal' - * @return string A random string of the type and length specified - */ - static public function generateRandomString($length, $type='alphanumeric') - { - if ($length < 1) { - fCore::toss( - 'fProgrammerException', - fGrammar::compose( - 'The length specified, %1$s, is less than the minimum of %2$s', - $length, - 1 - ) - ); - } - - switch ($type) { - case 'alphanumeric': - $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; - break; - - case 'alpha': - $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - break; - - case 'numeric': - $alphabet = '0123456789'; - break; - - case 'hexadecimal': - $alphabet = 'abcdef0123456789'; - break; - - default: - fCore::toss( - 'fProgrammerException', - fGrammar::compose( - 'The type specified, %1$s, is invalid. Must be one of: %2$s.', - fCore::dump($type) - ) - ); - } - - $alphabet_length = strlen($alphabet); - $output = ''; - - for ($i = 0; $i < $length; $i++) { - $output .= $alphabet[self::random(0, $alphabet_length-1)]; - } - - return $output; - } - - /** * Hashes a password using a loop of sha1 hashes and a salt, making rainbow table attacks infeasible * @@ -99,7 +41,7 @@ static public function generateRandomString($length, $type='alphanumeric') */ static public function hashPassword($password) { - $salt = self::generateRandomString(10); + $salt = self::randomString(10); return self::hashWithSalt($password, $salt); } @@ -273,6 +215,64 @@ static public function random($min=NULL, $max=NULL) } + /** + * Returns a random string of the type and length specified + * + * @param integer $length The length of string to return + * @param string $type The type of string to return, can be 'alphanumeric', 'alpha', 'numeric', or 'hexadecimal' + * @return string A random string of the type and length specified + */ + static public function randomString($length, $type='alphanumeric') + { + if ($length < 1) { + fCore::toss( + 'fProgrammerException', + fGrammar::compose( + 'The length specified, %1$s, is less than the minimum of %2$s', + $length, + 1 + ) + ); + } + + switch ($type) { + case 'alphanumeric': + $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; + break; + + case 'alpha': + $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + break; + + case 'numeric': + $alphabet = '0123456789'; + break; + + case 'hexadecimal': + $alphabet = 'abcdef0123456789'; + break; + + default: + fCore::toss( + 'fProgrammerException', + fGrammar::compose( + 'The type specified, %1$s, is invalid. Must be one of: %2$s.', + fCore::dump($type) + ) + ); + } + + $alphabet_length = strlen($alphabet); + $output = ''; + + for ($i = 0; $i < $length; $i++) { + $output .= $alphabet[self::random(0, $alphabet_length-1)]; + } + + return $output; + } + + /** * Makes sure that the PRNG has been seeded with a fairly secure value * diff --git a/classes/fORMColumn.php b/classes/fORMColumn.php index c56bfa98..6e7af191 100644 --- a/classes/fORMColumn.php +++ b/classes/fORMColumn.php @@ -616,7 +616,7 @@ static public function setRandomStrings($object, &$values, &$old_values, &$relat if ($unique_key == array($column)) { $is_unique_column = TRUE; do { - $value = fCryptography::generateRandomString($settings['length'], $settings['type']); + $value = fCryptography::randomString($settings['length'], $settings['type']); // See if this is unique $sql = "SELECT " . $column . " FROM " . $table . " WHERE " . $column . " = " . fORMDatabase::escapeByType($value); @@ -627,7 +627,7 @@ static public function setRandomStrings($object, &$values, &$old_values, &$relat // If is is not a unique column, just generate a value if (!$is_unique_column) { - $value = fCryptography::generateRandomString($settings['length'], $settings['type']); + $value = fCryptography::randomString($settings['length'], $settings['type']); } fActiveRecord::assign($values, $old_values, $column, $value);