1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-07-11 19:46:22 +02:00

Move method 'createRandomString' from class 'Auth' to 'UserManager'

This commit is contained in:
Marco
2017-02-21 09:13:39 +01:00
parent fdeff8a792
commit e916c3d07e
2 changed files with 18 additions and 18 deletions

View File

@ -1397,24 +1397,6 @@ final class Auth extends UserManager {
return $params;
}
/**
* Creates a random string with the given maximum length
*
* With the default parameter, the output should contain at least as much randomness as a UUID
*
* @param int $maxLength the maximum length of the output string (integer multiple of 4)
* @return string the new random string
*/
public static function createRandomString($maxLength = 24) {
// calculate how many bytes of randomness we need for the specified string length
$bytes = floor(intval($maxLength) / 4) * 3;
// get random data
$data = openssl_random_pseudo_bytes($bytes);
// return the Base64-encoded result
return Base64::encode($data, true);
}
/**
* Creates a UUID v4 as per RFC 4122
*

View File

@ -27,6 +27,24 @@ abstract class UserManager {
/** @var PdoDatabase the database connection to operate on */
protected $db;
/**
* Creates a random string with the given maximum length
*
* With the default parameter, the output should contain at least as much randomness as a UUID
*
* @param int $maxLength the maximum length of the output string (integer multiple of 4)
* @return string the new random string
*/
public static function createRandomString($maxLength = 24) {
// calculate how many bytes of randomness we need for the specified string length
$bytes = floor(intval($maxLength) / 4) * 3;
// get random data
$data = openssl_random_pseudo_bytes($bytes);
// return the Base64-encoded result
return Base64::encode($data, true);
}
/**
* @param PdoDatabase|PdoDsn|\PDO $databaseConnection the database connection to operate on
*/