vkomulai/finnish-ssn

createWithAge can create an invalid SSN

Closed this issue · 3 comments

niom commented

There is a possibility that generating the SSN based on age does not create valid SSN.

    for (let i = 0; i < 20; i++) {
        const ssn = FinnishSSN.createWithAge(20)
        const isValid = FinnishSSN.validate(ssn)
        console.log(`${i}: ${ssn} is valid: ${isValid}`)
    }

outputs:
0: 020200A5012 is valid: true
1: 200999A843W is valid: false
2: 161299A1103 is valid: false
3: 020300A623T is valid: true
4: 140400A7692 is valid: true
5: 080200A7266 is valid: true
6: 130200A488R is valid: true
7: 140600A142E is valid: true
8: 180200A672W is valid: true
9: 170300A230T is valid: true
10: 220100A357H is valid: true
11: 030500A805X is valid: true
12: 250899A181Y is valid: false
13: 301199A392D is valid: false
14: 060200A780M is valid: true
15: 061199A777B is valid: false
16: 190300A810T is valid: true
17: 090999A1105 is valid: false
18: 211299A6026 is valid: false
19: 010999A443R is valid: false
deanc commented

I can also now confirm this issue. Here are some samples that it generated for me that were invalid:

"160999A506E","091099A3302","261199A6195","301199A373T","241299A860E","251099A3866","171099A531P","021299A571X","241299A797D","121099A4617","111099A7297","231199A735Y","011099A653A","220999A457R","181299A885C","180999A141Y","180999A899D","071199A704M","061199A7759","301099A432W","131099A107E","160999A488V","101299A1041","031199A4894","240999A170S","031099A427A","081199A197X","061199A226K","021199A531U","151299A112H","190999A417H","171099A470R","141299A4271","131199A669C","131299A4216","181299A217U","231199A808A","021099A890L","311099A8534","151099A630L","121299A794K","061199A562D","041299A111C","161199A655V","221299A3069","111099A4175","291099A560C","301199A4144","131299A320X","230999A645E","281099A4462","041299A1964","221099A3879","261099A3600","111299A384P","281099A6311","221199A228Y","041199A671M","250999A8412","021299A521A","171099A214F","231299A4951","051299A772B"

This issue seems still be a problem. I got invalid: "260599A171V" from generator.
It seems that that generator sometimes assigns 'A' instead of '-' for SSN that are generated before year 2000

Problem seems to be with order of 'centurySign' calculation and 'birthDayPassed' functionality.
If has not passed current year is reduced by one.
This means that if the year happens to be 2000 then centurySign is first calculated as 'A' and after that if birthday has not passed year is reduced by one to 1999.

For fix we probably could just switch ordering of these code blocks.
To me it's bit unclear why do we care about birthday passing in first place.