```
sonata-project/google-authenticator 2.3.1 2.3.1 Library to integrate Google ...
```
Symfony packages
show
```
no result
```
PHP version
7.4.15
Subject
If one creates a GoogleAuthenticator instance with a 60-seconds code period:
$authenticator = new GoogleAuthenticator(6, 20, null, 60);
it's not possible to authenticate successfully while calling the checkCode() method.
I think the issue is caused by the ability to modify the $codePeriod but not the $periodSize. If one is going to calculate codes with a codePeriod = 60 and a periodSize = 30 (by default), checkCode() and getCode() will calculate codes for double as many codes (than with a codePeriod of 30) for 30 seconds periods which leads in all cases to non-matching codes. The wrong codes are caused by the variable $timeForCode which falsely calculates the amount of periods of 30 seconds since UNIX epoch but not the amount of 60 second periods.
To solve the issue I was able to set the periodSize via Reflection. A better way would be to allow the periodSize as a formal argument to the constructor.
Environment
Sonata packages
show
``` sonata-project/google-authenticator 2.3.1 2.3.1 Library to integrate Google ... ```
Symfony packages
show
``` no result ```
PHP version
Subject
If one creates a GoogleAuthenticator instance with a 60-seconds code period:
it's not possible to authenticate successfully while calling the
checkCode()
method.I think the issue is caused by the ability to modify the
$codePeriod
but not the$periodSize
. If one is going to calculate codes with a codePeriod = 60 and a periodSize = 30 (by default),checkCode()
andgetCode()
will calculate codes for double as many codes (than with a codePeriod of 30) for 30 seconds periods which leads in all cases to non-matching codes. The wrong codes are caused by the variable$timeForCode
which falsely calculates the amount of periods of 30 seconds since UNIX epoch but not the amount of 60 second periods.To solve the issue I was able to set the periodSize via Reflection. A better way would be to allow the periodSize as a formal argument to the constructor.