You are here

protected function TfaBasePlugin::generate in Two-factor Authentication (TFA) 7.2

Generate a random string of characters of length $this->codeLength.

Return value

string Generated random string of characters.

File

./tfa.inc, line 590
TFA module classes.

Class

TfaBasePlugin
Base plugin class.

Code

protected function generate() {
  $string = '';
  do {
    $chars = strtolower(base64_encode(drupal_random_bytes($this->codeLength)));

    // Remove some characters that are more difficult to distinguish or type.
    $string .= strtr($chars, array(
      '+' => '',
      '/' => '',
      '=' => '',
      '-' => '',
      '_' => '',
      '0' => '',
      'o' => '',
    ));
  } while (strlen($string) <= $this->codeLength);
  return substr($string, 0, $this->codeLength);
}