HermannBjorgvin / Kennitala

Icelandic national ID (kennitölur) utilities for servers and clients.
MIT License
36 stars 10 forks source link

isValid and isPerson pass when they should fail #16

Closed stefanhar closed 3 years ago

stefanhar commented 3 years ago

The national id 1337991337 passes isValid and isPerson checks.

const { isPerson, isValid } = require('kennitala')
const nationalId = '1337991337'
console.log('isValid(nationalId)', isValid(nationalId))
console.log('isPerson(nationalId)', isPerson(nationalId))
HermannBjorgvin commented 3 years ago

Looks like we are not checking the months being 01-12, will add a fix and version bump to 1.2.6 this weekend.

Thanks for opening an issue

HermannBjorgvin commented 3 years ago

If you want to NPM patch your local version you could change the isPerson and isCompany functions

    function isPerson(kt) {
        var d = parseInt(kt.substr(0, 2), 10);
        var y = parseInt(kt.substr(2, 4), 10);

        return d > 0 && d <= 31 && y > 0 && y <= 12;
    }

    // Companies have first two characters between 41-71
    function isCompany(kt) {
        var d = parseInt(kt.substr(0, 2), 10);
        var y = parseInt(kt.substr(2, 4), 10);

        return d > 40 && d <= 71 && y > 0 && y <= 12;
    }
HermannBjorgvin commented 3 years ago

Went ahead and fixed this in 1.2.6 #17

Thanks for the help