|
Christopher taylor - 2009-12-08 09:00:00
When running TOTP under php 5.2.11 it falses to generate the otp correctly. I have narrowed it down to this line.
$otp = $binary % pow(10, $this->codeDigitsNr);
specifically the modulus gives bool(false) instead of an integer.
Protung Dragos - 2009-12-08 15:16:44 - In reply to message 1 from Christopher taylor
I have test it on PHP 5.2.11 and everything is ok.
What exactly do you get as a password ?
Can you past the output of example.php from the package ?
Christopher taylor - 2009-12-08 16:26:45 - In reply to message 2 from Protung Dragos
Hi
It only fails on my hosting company's server. The otp I get is 0000000010
If i use fmod($binary , pow(10, $this->codeDigitsNr));
It seems to work fine. I am now sure why it's failing though. I will get some output from the example later and post to you.
Im using a free hosting company called bytehost.com
You can setup a free account to test its immediate access.
Thanks
Protung Dragos - 2009-12-08 16:55:26 - In reply to message 3 from Christopher taylor
This is very strange. i will try to setup an account later and test it out, but don't have time right now, so first i'll wait for your replay with the output from example
Christopher taylor - 2009-12-08 18:17:51 - In reply to message 4 from Protung Dragos
Hi
I uploaded the example. It works with default number of digits but fails with 10 (which is what Ive been using).
here is the o/p with default setting. Notice to 0 seconds all the time. i think the problem is due to the integer length. The seconds produce fine on my pc.
Original time : 1260290364
Original password : 1477860
Expiration time: 30s
1260290364| Code:1477860 -> true (after 0 seconds)
1260290364| Code:1477860 -> true (after 0 seconds)
1260290364| Code:1477860 -> true (after 0 seconds)
Protung Dragos - 2009-12-08 22:35:21 - In reply to message 5 from Christopher taylor
I have made an update to the class. Please download the new version and let me know if there are still problems.
I have test it (10 second availability and 10 digits code) on PHP 5.2.9 and 5.2.11 and it worked fine.
Christopher taylor - 2009-12-09 05:34:22 - In reply to message 6 from Protung Dragos
Hi
Still get an error.
I added a few var_dumps to the code
$binary = ( ($hash[$offset] & 0x7f) << 24) | (($hash[$offset + 1] & 0xff) << 16) | (($hash[$offset + 2] & 0xff) << 8) | ($hash[$offset + 3] & 0xff);
print "binary: " . var_dump($binary) . "<P>";
print "codeDigitsNr: " . var_dump($this->codeDigitsNr) . "<P>";
print "pow: " . var_dump(pow(10,$this->codeDigitsNr)) . "<P>";
print "binary % power(): " . var_dump($binary % pow(10, $this->codeDigitsNr)) . "<P>";
$otp = $binary % pow(10, $this->codeDigitsNr);
print "otp: " . $otp . "<P>";
Here is the o/p from that on my hosted server
int(437599974) binary:
int(10) codeDigitsNr:
float(10000000000) pow:
bool(false) binary % power():
Original time : 1260336556
Original password : 0000000000
Expiration time: 10s
int(437599974)
binary:
int(10) codeDigitsNr:
float(10000000000) pow:
bool(false) binary % power():
1260336556| Code:0000000000 -> true (after 0 seconds)
Christopher taylor - 2009-12-09 05:40:11 - In reply to message 7 from Christopher taylor
Here is the same code but with number of digits set to 7
int(262516703) binary:
int(7) codeDigitsNr:
int(10000000) pow:
int(2516703) binary % power():
otp: 2516703
Original time : 1260337071
Original password : 2516703
Expiration time: 10s
int(262516703)
binary:
int(7) codeDigitsNr:
int(10000000) pow:
int(2516703) binary % power():
otp: 2516703
1260337071| Code:2516703 -> true (after 0 seconds)
It really seems to do with the maths when the digit length i slong, and only on this company's server.
Protung Dragos - 2009-12-09 08:22:46 - In reply to message 8 from Christopher taylor
yes, it seems so. could you var_dump the result of the pow() ?
$pow = pow(10,$this->codeDigitsNr);
var_dump($pow);
var_dump($binary);
var_dump($binary % pow(10, $this->codeDigitsNr));
Is the error now happening on the example.php or your test code ?
Also what is the value of PHP_INT_MAX in php.ini ?
Christopher taylor - 2009-12-09 09:24:48 - In reply to message 9 from Protung Dragos
I did dump the pow, in my dumps in previous messages.
float(10000000000) pow: (when 10 digits)
int(10000000) pow: (when 8 digits)
I don't have access to php.ini, but I var_dump'd the value
int(2147483647)
|