protected function TfaBasicSms::generate in TFA Basic plugins 7
Generate a random string of characters of length $this->codeLength.
Return value
string Generated random string of characters.
Overrides TfaBasePlugin::generate
3 calls to TfaBasicSms::generate()
- TfaBasicSms::begin in includes/
tfa_sms.inc - TFA process begin.
- TfaBasicSms::submitForm in includes/
tfa_sms.inc - Submit form.
- TfaBasicSmsSetup::begin in includes/
tfa_sms.inc - TFA process begin.
File
- includes/
tfa_sms.inc, line 109
Class
Code
protected function generate() {
$allowable_characters = '0123456789';
// Zero-based count of characters in the allowable list:
$len = strlen($allowable_characters) - 1;
// Declare the password as a blank string.
$string = '';
// Loop the number of times specified by codeLength.
for ($i = 0; $i < $this->codeLength; $i++) {
do {
// Find a secure random number within the range needed.
$index = ord(drupal_random_bytes(1));
} while ($index > $len);
// Each iteration, pick a random character from the
// allowable string and append it to the password:
$string .= $allowable_characters[$index];
}
return $string;
}