🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

com.github.vladislavgoltjajev:java-personal-code

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.github.vladislavgoltjajev:java-personal-code

Lightweight library for working with government-issued personal identification codes.

1.6
Source
Maven
Version published
Maintainers
1
Source

Java Personal Code

Maven Central License

Lightweight library for working with government-issued personal identification codes.

Import

Java 8 or higher is required for the library to work.

Gradle

dependencies {
    implementation 'com.github.vladislavgoltjajev:java-personal-code:X.X'
}

Maven


<dependency>
    <groupId>com.github.vladislavgoltjajev</groupId>
    <artifactId>java-personal-code</artifactId>
    <version>X.X</version>
</dependency>

Usage

public class Test {

    /**
     * Example operations using an Estonian personal code.
     */
    public static void main(String[] args) {
        // Generate personal code.
        EstonianPersonalCodeGenerator generator = new EstonianPersonalCodeGenerator();
        String personalCode = generator.generateRandomPersonlCode(); // 37209030023
        // Validate personal code.
        EstonianPersonalCodeValidator validator = new EstonianPersonalCodeValidator();
        boolean isValidFormat = validator.isValidFormat(personalCode); // true
        boolean isValid = validator.isValid(personalCode); // true
        // Extract data from personal code.
        EstonianPersonalCodeParser parser = new EstonianPersonalCodeParser();
        LocalDate dateOfBirth = parser.getDateOfBirth(personalCode); // 03.09.1972
        Gender gender = parser.getGender(personalCode); // MALE
        int birthOrderNumber = parser.getBirthOrderNumber(personalCode); // 2
    }
}

API

Estonia

GYYMMDDXXXC

  • G - gender and birth century indicator (1, 3, 5 - male; 2, 4, 6 - female)
  • YYMMDD - date of birth
  • XXX - birth order number
  • C - checksum

Example: 47508030046.

EstonianPersonalCodeValidator

MethodReturn typeDescription
isValid(String personalCode)booleanChecks if the Estonian personal code is valid.
isValidFormat(String personalCode)boolean Checks if the Estonian personal code conforms to the correct format.
Does not check the integrity of the personal code or the validity of the embedded data.

EstonianPersonalCodeParser

MethodReturn typeDescription
getGender(String personalCode)GenderReturns the person's gender (first digit).
getDateOfBirth(String personalCode)LocalDateReturns the person's date of birth (digits 2-7).
getAge(String personalCode)PeriodReturns the person's age.
getBirthOrderNumber(String personalCode)intReturns the person's birth order number (digits 8-10).

EstonianPersonalCodeGenerator

MethodReturn typeDescription
generateRandomPersonalCode()StringGenerates a random Estonian personal code.
generatePersonalCode(Gender gender)String Generates an Estonian personal code using the given gender.
The date of birth and birth order number are generated randomly.
generatePersonalCode(Gender gender, LocalDate dateOfBirth)String Generates an Estonian personal code using the given gender and date of birth.
The birth order number is generated randomly.
generatePersonalCode(Gender gender, LocalDate dateOfBirth, int birthOrderNumber)StringGenerates an Estonian personal code using the given gender, date of birth and birth order number.

India

XXXX-XXXX-XXXC

  • XXXX-XXXX-XXX - random numbers
  • C - checksum (Verhoeff algorithm)

Example: 9185-8655-0944.

IndianPersonalCodeValidator

MethodReturn typeDescription
isValid(String personalCode)booleanChecks if the Indian personal code is valid.
isValidFormat(String personalCode)boolean Checks if the Indian personal code conforms to the correct format.
Does not check the integrity of the personal code.

IndianPersonalCodeGenerator

MethodReturn typeDescription
generatePersonalCode()StringGenerates an Indian personal code.

Latvia

32XXXX-XXXXC (updated format since 01.07.2017)

  • 32 - updated format indicator
  • XXXX-XXXX - random numbers
  • C - checksum

Example: 323691-93794.

YYMMDD-BXXXC (legacy format)

  • YYMMDD - date of birth
  • B - birth century indicator (0 - 19th, 1 - 20th, 2 - 21st)
  • XXX - birth order number
  • C - checksum

Example: 290156-11605.

LatvianPersonalCodeValidator

MethodReturn typeDescription
isValid(String personalCode)booleanChecks if the Latvian personal code (either updated or legacy) is valid.
isValidUpdatedPersonalCode(String personalCode)booleanChecks if the updated Latvian personal code is valid.
isValidLegacyPersonalCode(String personalCode)booleanChecks if the legacy Latvian personal code is valid.
isValidFormat(String personalCode)boolean Checks if the specified Latvian personal code conforms to the correct legacy or updated format.
Does not check the integrity of the personal code or the validity of the embedded data.
isValidUpdatedFormat(String personalCode)boolean Checks if the updated Latvian personal code conforms to the correct format.
Does not check the integrity of the personal code.
isValidLegacyFormat(String personalCode)boolean Checks if the legacy Latvian personal code conforms to the correct format.
Does not check the integrity of the personal code or the validity of the embedded data.

LatvianPersonalCodeParser

:exclamation: Only works with legacy Latvian personal codes.

MethodReturn typeDescription
getDateOfBirth(String personalCode)LocalDateReturns the person's date of birth (digits 1-6).
getAge(String personalCode)PeriodReturns the person's age.
getBirthOrderNumber(String personalCode)intReturns the person's birth order number (digits 8-10).

LatvianPersonalCodeGenerator

MethodReturn typeDescription
generateRandomPersonalCode()StringGenerates a random Latvian personal code.
generateRandomUpdatedPersonalCode()String Generates a random updated Latvian personal code.
May contain a dash between the 6th and 7th digit.
generateRandomUpdatedPersonalCode(boolean addDash)StringGenerates a random updated Latvian personal code.
generateRandomLegacyPersonalCode()StringGenerates a random legacy Latvian personal code.
generateLegacyPersonalCode(LocalDate dateOfBirth)String Generates a legacy Latvian personal code using the given date of birth.
The birth order number is generated randomly.
generateLegacyPersonalCode(LocalDate dateOfBirth, int birthOrderNumber)StringGenerates a legacy Latvian personal code using the given date of birth and birth order number.

Lithuania

GYYMMDDXXXC

  • G - gender and birth century indicator (1, 3, 5 - male; 2, 4, 6 - female)
  • YYMMDD - date of birth
  • XXX - birth order number
  • C - checksum

Example: 50109130003.

LithuanianPersonalCodeValidator

MethodReturn typeDescription
isValid(String personalCode)booleanChecks if the Lithuanian personal code is valid.
isValidFormat(String personalCode)boolean Checks if the Lithuanian personal code conforms to the correct format.
Does not check the integrity of the personal code or the validity of the embedded data.

LithuanianPersonalCodeParser

MethodReturn typeDescription
getGender(String personalCode)GenderReturns the person's gender (first digit).
getDateOfBirth(String personalCode)LocalDateReturns the person's date of birth (digits 2-7).
getAge(String personalCode)PeriodReturns the person's age.
getBirthOrderNumber(String personalCode)intReturns the person's birth order number (digits 8-10).

LithuanianPersonalCodeGenerator

MethodReturn typeDescription
generateRandomPersonalCode()StringGenerates a random Lithuanian personal code.
generatePersonalCode(Gender gender)String Generates a Lithuanian personal code using the given gender.
The date of birth and birth order number are generated randomly.
generatePersonalCode(Gender gender, LocalDate dateOfBirth)String Generates a Lithuanian personal code using the given gender and date of birth.
The birth order number is generated randomly.
generatePersonalCode(Gender gender, LocalDate dateOfBirth, int birthOrderNumber)StringGenerates a Lithuanian personal code using the given gender, date of birth and birth order number.

Luxembourg

YYYYMMDDXXXCC

  • YYYYMMDD - date of birth
  • XXX - birth order number
  • CC - checksum (Luhn and Verhoeff algorithms)

Example: 1944051267737.

LuxembourgishPersonalCodeValidator

MethodReturn typeDescription
isValid(String personalCode)booleanChecks if the Luxembourgish personal code is valid.
isValidFormat(String personalCode)boolean Checks if the Luxembourgish personal code conforms to the correct format.
Does not check the integrity of the personal code or the validity of the embedded data.

LuxembourgishPersonalCodeParser

MethodReturn typeDescription
getDateOfBirth(String personalCode)LocalDateReturns the person's date of birth (digits 1-8).
getAge(String personalCode)PeriodReturns the person's age.
getBirthOrderNumber(String personalCode)intReturns the person's birth order number (digits 9-11).

LuxembourgishPersonalCodeGenerator

MethodReturn typeDescription
generateRandomPersonalCode()StringGenerates a random Luxembourgish personal code.
generatePersonalCode(LocalDate dateOfBirth)String Generates a Luxembourgish personal code using the given date of birth.
The birth order number is generated randomly.
generatePersonalCode(LocalDate dateOfBirth, int birthOrderNumber)StringGenerates a Luxembourgish personal code using the given date of birth and birth order number.

Taiwan

RGXXXXXXXC

  • R - household registration region (A-Z)
  • G - gender indicator (1 - male, 2 - female)
  • XXXXXXX - random number
  • C - checksum

Example: R172192293.

TaiwanesePersonalCodeValidator

MethodReturn typeDescription
isValid(String personalCode)booleanChecks if the Taiwanese personal code is valid.
isValidFormat(String personalCode)boolean Checks if the Taiwanese personal code conforms to the correct format.
Does not check the integrity of the personal code.

TaiwanesePersonalCodeParser

MethodReturn typeDescription
getHouseholdRegistrationRegion(String personalCode)TaiwaneseRegionReturns the person's household registration region (first letter).
getGender(String personalCode)GenderReturns the person's gender (first digit).

TaiwanesePersonalCodeGenerator

MethodReturn typeDescription
generateRandomPersonalCode()StringGenerates a random Taiwanese personal code.
generatePersonalCode(TaiwaneseRegion region)String Generates a Taiwanese personal code using the given household registration region.
The gender is generated randomly.
generatePersonalCode(Gender gender)String Generates a Taiwanese personal code using the given gender.
The household registration region is generated randomly.
generatePersonalCode(TaiwaneseRegion region, Gender gender)String Generates a Taiwanese personal code using the given household registration region and gender.
The household registration region is not checked for validity.
generatePersonalCode(TaiwaneseRegion region, Gender gender, boolean checkRegionValidity)StringGenerates a Taiwanese personal code using the given household registration region and gender and checks if the given household registration region is valid.

United Arab Emirates

784-YYYY-XXXXXXX-C

  • 784 - ISO 3166-1 numeric code for the UAE
  • YYYY - year of birth
  • XXXXXXX - random number
  • C - checksum (Luhn algorithm)

Example: 784-1935-0284231-8.

EmiratiPersonalCodeValidator

MethodReturn typeDescription
isValid(String personalCode)booleanChecks if the Emirati personal code is valid.
isValidFormat(String personalCode)boolean Checks if the Emirati personal code conforms to the correct format.
Does not check the integrity of the personal code.

EmiratiPersonalCodeParser

MethodReturn typeDescription
getBirthYear(String personalCode)intReturns the person's birth year (digits 4-7).

EmiratiPersonalCodeGenerator

MethodReturn typeDescription
generateRandomPersonalCode()StringGenerates a random Emirati personal code.
generatePersonalCode(LocalDate dateOfBirth)StringGenerates an Emirati personal code using the given date of birth.
generatePersonalCode(int birthYear)StringGenerates an Emirati personal code using the given birth year.

FAQs

Package last updated on 26 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts