Archaeology-ABM / nassa-hs

The nassa command line tool searches, validates and lists NASSA modules
MIT License
3 stars 1 forks source link

Better ORCID validation #5

Closed nevrome closed 2 years ago

nevrome commented 2 years ago

The last character in the ORCID iD is a checksum. In accordance with ISO/IEC 7064:2003, MOD 11-2, this checksum must be "0" - "9" or "X", a capital letter X which represents the value 10.

https://support.orcid.org/hc/en-us/articles/360006897674-Structure-of-the-ORCID-Identifier

nevrome commented 2 years ago

This first issue is fixed. For the future: Implement ORCID checksum checking according to this algorithm

/** 
  * Generates check digit as per ISO 7064 11,2. 
  * 
  */ 
public static String generateCheckDigit(String baseDigits) { 
    int total = 0; 
    for (int i = 0; i < baseDigits.length(); i++) { 
        int digit = Character.getNumericValue(baseDigits.charAt(i)); 
        total = (total + digit) * 2; 
    } 
    int remainder = total % 11; 
    int result = (12 - remainder) % 11; 
    return result == 10 ? "X" : String.valueOf(result); 
}
nevrome commented 2 years ago

This is now implemented in #11