To address the issue of fake export licenses, we need a robust validation system that checks both the format and authenticity of license numbers. Below is a Python implementation that validates export licenses against predefined criteria and a database of known fake licenses.
Solution Code
import re
FAKE_LICENSES = {
"ABC1234567", "XYZ9876543", "DEF4567890"
}
def validate_export_license(license_number):
"""
Validates an export license number based on format and authenticity.
Args:
license_number (str): The license number to validate.
Returns:
bool: True if valid, False otherwise.
"""
# Check length
if len(license_number) != 10:
return False
# Check format: 3 uppercase letters followed by 7 digits
if not re.fullmatch(r'^[A-Z]{3}\d{7}$', license_number):
return False
# Check against fake licenses
if license_number in FAKE_LICENSES:
return False
return True
# Example usage
if __name__ == "__main__":
test_licenses = [
"ABC1234567", # Fake (in FAKE_LICENSES)
"XYZ9876543", # Fake (in FAKE_LICENSES)
"DEF4567890", # Fake (in FAKE_LICENSES)
"LMN1234567", # Valid (correct format, not fake)
"abc1234567", # Invalid (lowercase letters)
"AB1234567", # Invalid (too short)
"AB12345678", # Invalid (too long)
"AB!234567", # Invalid (contains non-alphanumeric)
]
for license_num in test_licenses:
is_valid = validate_export_license(license_num)
print(f"License {license_num}: {'Valid' if is_valid else 'Invalid'}")
Explanation
-
Format Validation:
- The license number must be exactly 10 characters long.
- The first 3 characters must be uppercase letters (A-Z).
- The remaining 7 characters must be digits (0-9).
- This is enforced using a regular expression:
^[A-Z]{3}\d{7}$.
-
Fake License Check:
- A predefined set
FAKE_LICENSEScontains known invalid license numbers. - If the input license matches any entry in this set, it is rejected.
- A predefined set
-
Example Usage:
The test cases demonstrate valid and invalid scenarios, including correct format, incorrect format, and known fake licenses.
Output
License ABC1234567: Invalid
License XYZ9876543: Invalid
License DEF4567890: Invalid
License LMN1234567: Valid
License abc1234567: Invalid
License AB1234567: Invalid
License AB12345678: Invalid
License AB!234567: Invalid
Key Points
- Security: Combines structural checks with a database of known fakes to prevent bypassing via format manipulation.
- Efficiency: Regular expressions ensure fast format validation, while set lookups provide O(1) time complexity for fake license checks.
- Extensibility: The
FAKE_LICENSESset can be updated dynamically as new fake licenses are identified.
This solution effectively filters out fake export licenses by leveraging strict format rules and a blacklist of known fraudulent entries.
Request an On-site Audit / Inquiry