Contact ID validation improvements

This commit is contained in:
Pinga 2023-08-28 13:48:40 +03:00
parent 019fd891b3
commit dd6ec728cc
2 changed files with 13 additions and 8 deletions

View file

@ -5,7 +5,7 @@ function processContactCreate($conn, $db, $xml, $clid, $database_type, $trans) {
$clTRID = (string) $xml->command->clTRID;
if (!$contactID) {
sendEppError($conn, $db, 2003, 'Identifier type minLength value=3, maxLength value=16', $clTRID, $trans);
sendEppError($conn, $db, 2003, 'Please provide a contact ID', $clTRID, $trans);
return;
}

View file

@ -116,19 +116,24 @@ function getHost(PDO $db, $id) {
function validate_identifier($identifier) {
if (!$identifier) {
return 'Abstract client and object identifier type minLength value=3';
return 'Please provide a contact ID';
}
if (strlen($identifier) < 3) {
return 'Abstract client and object identifier type minLength value=3';
$length = strlen($identifier);
if ($length < 3) {
return 'Identifier type minLength value=3, maxLength value=16';
}
if (strlen($identifier) > 16) {
return 'Abstract client and object identifier type maxLength value=16';
if ($length > 16) {
return 'Identifier type minLength value=3, maxLength value=16';
}
if (preg_match('/[^A-Z0-9\-]/', $identifier)) {
return 'The ID of the contact must contain letters (A-Z) (ASCII) hyphen (-), and digits (0-9). Registry assigns each registrar a unique prefix with which that registrar must create contact IDs.';
$pattern1 = '/^[A-Z]+\-[0-9]+$/';
$pattern2 = '/^[A-Za-z][A-Z0-9a-z]*$/';
if (!preg_match($pattern1, $identifier) && !preg_match($pattern2, $identifier)) {
return 'The ID of the contact must contain letters (A-Z) (ASCII), hyphen (-), and digits (0-9).';
}
}