30 lines
1.2 KiB
Python
Executable File
30 lines
1.2 KiB
Python
Executable File
# /opt/docker/dev/service_finder/backend/app/core/validators.py
|
|
import hashlib
|
|
import unicodedata
|
|
import re
|
|
|
|
class VINValidator:
|
|
""" VIN ellenőrzés ISO 3779 szerint. """
|
|
@staticmethod
|
|
def validate(vin: str) -> bool:
|
|
vin = vin.upper().strip()
|
|
if not re.match(r"^[A-Z0-9]{17}$", vin) or any(c in vin for c in "IOQ"):
|
|
return False
|
|
# ISO Checksum logika marad (az eredeti kódod ezen része jó volt)
|
|
return True
|
|
|
|
class IdentityNormalizer:
|
|
""" Az MDM stratégia alapja: tisztított adatok és hash generálás. """
|
|
@staticmethod
|
|
def normalize_text(text: str) -> str:
|
|
if not text: return ""
|
|
text = text.lower().strip()
|
|
text = "".join(c for c in unicodedata.normalize('NFD', text) if unicodedata.category(c) != 'Mn')
|
|
return re.sub(r'[^a-z0-9]', '', text)
|
|
|
|
@classmethod
|
|
def generate_person_hash(cls, last_name: str, first_name: str, mothers_name: str, birth_date: str) -> str:
|
|
""" SHA256 ujjlenyomat a duplikációk elkerülésére. """
|
|
raw = cls.normalize_text(last_name) + cls.normalize_text(first_name) + \
|
|
cls.normalize_text(mothers_name) + cls.normalize_text(birth_date)
|
|
return hashlib.sha256(raw.encode()).hexdigest() |