gordonmcvey / reefknot

Reefknot framework for PHP
Apache License 2.0
5 stars 0 forks source link

Luhn prop can't handle typical credit card numbers on 32 bit systems #4

Closed gordonmcvey closed 12 years ago

gordonmcvey commented 12 years ago

If a number such a 4111111111111111 (should pass) or 4111111111111119 (should fail) is passed to the Luhn validation prop, the result is an invalidartumentexception is thrown. This is because the above numbers exceed the maximum size for integers on 32 bit builds of PHP and get converted to float.

If the prop is modified to accept floats, both of the examples above get treated as 4.1111111111111E+15, which are indistinguishable, and the number that should fail (the one ending in 9) actually ended up being passed as valid.

Seeing as typical credit card numbers are 16-20 digits long, and the Luhn check is most typically used as a sanity check on credit card numbers, this is a problem

This doesn't happen on 64 bit builds.

gordonmcvey commented 12 years ago

Luhn has been updated to accept floats and strings (if they're purely strings of digits) in order to work around this issue.