Ejemplo n.º 1
0
        public int CountCheckSum(string pesel)
        {
            int sum = 0;

            if (pesel.Length == PeselStruct.PeselSize)
            {
                PeselStruct peselObj = new PeselStruct(pesel);

                for (int i = 0; i < Weights.Length; i++)
                {
                    sum += Weights[i] * peselObj[i];
                }
            }

            int checkDigit = sum % 10;

            return(checkDigit == 0 ? 0 : 10 - checkDigit);
        }
Ejemplo n.º 2
0
        public bool IsPeselValid(string pesel)
        {
            // Check if is number and 11 digit long
            if (pesel.Length == PeselStruct.PeselSize)
            {
                PeselStruct peselObj = new PeselStruct(pesel);

                // Check birth date
                if (DateValidator.IsDateValid(peselObj.Year, peselObj.Month, peselObj.Day))
                {
                    // Count weighted sum: 1 3 7 9 1 3 7 9 1 3
                    int lastDigit = CountCheckSum(pesel);
                    // 11th digit is check sum digit
                    return(lastDigit == peselObj[10]);
                }
            }
            return(false);
        }