DB Schema information
Your DB should have a column called password which stores passwords using this format:
PHP
$pass = base64_encode(sha1("password", true));
You can easily change the algorithm/format to whatever you want.
Then you should also have a column called otpkey . The otpkey will store the key in base16 format.
If you would like to make it easier for your users to manage their keys you can convert the base from base32 to base16. The reason why you would want to do such a thing is because Google Authenticator expects keys in base32 and this middleware expects them in base16.
Here is a PHP function you can use to convert back and forth:
<?php function convBase($numberInput, $fromBaseInput, $toBaseInput) { if ($fromBaseInput==$toBaseInput) return $numberInput; $fromBase = str_split($fromBaseInput,1); $toBase = str_split($toBaseInput,1); $number = str_split($numberInput,1); $fromLen=strlen($fromBaseInput); $toLen=strlen($toBaseInput); $numberLen=strlen($numberInput); $retval=''; if ($toBaseInput == '0123456789') { $retval=0; for ($i = 1;$i <= $numberLen; $i++) $retval = bcadd($retval, bcmul(array_search($number[$i-1], $fromBase),bcpow($fromLen,$numberLen-$i))); return $retval; } if ($fromBaseInput != '0123456789') $base10=convBase($numberInput, $fromBaseInput, '0123456789'); else $base10 = $numberInput; if ($base10<strlen($toBaseInput)) return $toBase[$base10]; while($base10 != '0') { $retval = $toBase[bcmod($base10,$toLen)].$retval; $base10 = bcdiv($base10,$toLen,0); } return $retval; } $b16 = convBase("BASE32 CHARS", 'abcdefghijklmnopqrstuvwxyz234567', '0123456789abcdef'); $b32 = convBase("BASE16 CHARS", '0123456789abcdef', 'abcdefghijklmnopqrstuvwxyz234567');
If you want to perform a one-time conversion you can use this tool.