You are here

public static function Google2FA::generateSecretKey in Google Authenticator login 7

Generates a 16 digit secret key in base32 format.

Parameters

int $length: Length of the key

Return value

string Secret key

File

tests/ga_login_test/ga_login_test.module, line 96
ga_login_test module.

Class

Google2FA
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Code

public static function generateSecretKey($length = 16) {
  $b32 = "234567QWERTYUIOPASDFGHJKLZXCVBNM";
  $s = "";
  for ($i = 0; $i < $length; $i++) {
    $s .= $b32[rand(0, 31)];
  }
  return $s;
}