corbanworks / fng-sin-tools

Generate and validate Canadian social insurance numbers using PHP.
http://www.fakenamegenerator.com/social-insurance-number.php
42 stars 30 forks source link

Doesn't pass validation #1

Open catbadger opened 6 years ago

catbadger commented 6 years ago

Try validating the generated SINs against the government guidelines, and it fails every time there's an invalid prefix digit. I'm seeing 8's and 0's coming back from the function as it is and I'm digging in to figure out why.


UPDATE

OK maybe it's my php implementation, but the array_rand line is returning stuff not in the $validPrefix array. I was seeing zeros as the first character, which broke validation.

    $validPrefix = array(1,2,3,4,5,6,7,9);
    $sin = array_rand($validPrefix,1);

my code now looks like this, and works every time.

    $valid_first_char = array('1', '2', '3', '4', '5', '6', '7', '9' );
    $sin = $valid_first_char[ rand(0, (sizeof($valid_first_char) -1 ) ) ];
jacoballred commented 6 years ago

I'm pretty sure array_rand isn't being used properly there. I've re-opened this issue so I don't forget to fix this.