المكتبة التقنية ←

تسجيل الدخول المخصص في Oracle APEX: راجع قواعد اسم المستخدم قبل كود كلمة المرور

English version

My earlier LinkedIn post explored a custom authentication function in Oracle APEX. Before implementing the password comparison, there is another design decision worth checking: what exactly identifies an account?

If Alice, ALICE, and Alice can reach the same account in one component but different accounts in another, even a correct password verifier can sit behind an inconsistent identity model. This walkthrough uses synthetic data to expose that problem before changing a login flow.

Separate the login flow from the credential verifier

An authentication scheme establishes identity; APEX then exposes the signed-in identity through APP_USER. Prefer an available preconfigured scheme when it fits your identity provider and operational requirements. Custom authentication means owning the integration and its failure paths, not only writing a Boolean function. Oracle: authentication concepts

For a username/password scheme, APEX_AUTHENTICATION.LOGIN invokes the scheme's credential check, then handles successful post-authentication processing, logging, and redirection. Its p_uppercase_username parameter defaults to TRUE. That default matters when the account repository distinguishes letter case. Oracle: LOGIN API

Run a normalization preflight with disposable data

Suppose a proposed policy treats usernames as case-insensitive and ignores surrounding spaces. This query demonstrates the resulting collisions without creating or changing a table:

with demo_users (user_id, login_name) as (
    select 101, 'Alice' from dual union all
    select 102, 'ALICE' from dual union all
    select 103, ' bob ' from dual union all
    select 104, 'BOB'   from dual union all
    select 105, 'Carla' from dual
)
select upper(trim(login_name)) as login_key,
       count(*) as matching_accounts
from demo_users
group by upper(trim(login_name))
having count(*) > 1
order by login_key;

Expected rows for these ASCII examples:

LOGIN_KEY  MATCHING_ACCOUNTS
ALICE      2
BOB        2

Those are two different account records competing for each proposed key. Resolve the ownership and migration policy before enforcing uniqueness. Do not arbitrarily select the first matching record.

This is a design probe, not a universal username rule. A tenant-specific identity may need a composite key including the tenant. International names require an explicit policy for Unicode, collation, and normalization; this ASCII demonstration does not settle those rules. Apply your chosen policy consistently to registration, lookup, recovery, and account linking.

Make APEX's case handling explicit

If your reviewed identity policy deliberately preserves case, an illustrative login-page process with existing username and password items can call:

begin
    apex_authentication.login(
        p_username           => :P9999_USERNAME,
        p_password           => :P9999_PASSWORD,
        p_uppercase_username => false
    );
end;

Adapt the item names and review the active authentication scheme before use. Put this call in the login process; the scheme's verifier supplies its credential decision. Changing the parameter alone does not migrate existing account keys or fix a conflicting lookup query. Never uppercase or trim the password to mirror a username rule.

Give password storage its own contract

A single SHA-512 hash, even with concatenated account fields, is not a modern adaptive password-storage design. Use a maintained verifier implementing a suitable password-hashing scheme such as Argon2id, with per-password salts and reviewed work factors. Retain the algorithm and parameters needed for verification and upgrades. OWASP: password storage

Define a generic user-facing failure response, controlled login throttling, recovery behavior, and appropriate multifactor authentication. Keep detailed diagnostics protected and exclude credentials from logs. OWASP: authentication guidance

Before rollout, test valid credentials, wrong passwords, unknown and disabled accounts, case variants, whitespace, duplicate normalized names, and verifier failure. Check the resulting APP_USER and account mapping. The examples above illustrate design and expected results; they do not implement a complete credential service or assert a measured performance improvement.

Original LinkedIn post

النسخة العربية

تناولت في بوست سابق على LinkedIn دالة تسجيل دخول مخصصة في Oracle APEX. قبل تنفيذ مقارنة كلمة المرور، فيه قرار تصميمي آخر يستحق المراجعة: إيه بالضبط اللي بيحدد هوية الحساب؟

لو Alice وALICE وAlice بيوصلوا لنفس الحساب في جزء من النظام، ولحسابات مختلفة في جزء آخر، ممكن يبقى عندك تحقق صحيح من كلمة المرور فوق نموذج هوية غير متسق. المثال التالي يستخدم بيانات افتراضية لكشف المشكلة قبل تغيير مسار تسجيل الدخول.

افصل مسار الدخول عن التحقق من بيانات الاعتماد

Authentication Scheme بتحدد الهوية، وبعدها APEX تتيح هوية المستخدم المسجّل دخوله من خلال APP_USER. فضّل Scheme جاهزة متاحة عندما تناسب مزوّد الهوية ومتطلبات التشغيل. اختيار Custom Authentication معناه تحمّل مسؤولية التكامل ومسارات الفشل، مش مجرد كتابة دالة ترجع Boolean. Oracle: مفاهيم تسجيل الدخول

في Scheme تستخدم اسم المستخدم وكلمة المرور، تستدعي APEX_AUTHENTICATION.LOGIN التحقق من بيانات الاعتماد، ثم تدير معالجة ما بعد نجاح الدخول والتسجيل وإعادة التوجيه. القيمة الافتراضية للمعامل p_uppercase_username هي TRUE. التفصيلة دي مهمة لو مستودع الحسابات بيفرّق بين الحروف الكبيرة والصغيرة. Oracle: توثيق LOGIN

اختبر قواعد توحيد الأسماء ببيانات مؤقتة

افترض إن السياسة المقترحة لا تفرّق بين حالة الحروف في اسم المستخدم وتتجاهل المسافات المحيطة. الاستعلام التالي يوضح التعارضات الناتجة، بدون إنشاء جدول أو تعديل بيانات:

with demo_users (user_id, login_name) as (
    select 101, 'Alice' from dual union all
    select 102, 'ALICE' from dual union all
    select 103, ' bob ' from dual union all
    select 104, 'BOB'   from dual union all
    select 105, 'Carla' from dual
)
select upper(trim(login_name)) as login_key,
       count(*) as matching_accounts
from demo_users
group by upper(trim(login_name))
having count(*) > 1
order by login_key;

الصفوف المتوقعة لهذه الأمثلة بحروف ASCII:

LOGIN_KEY  MATCHING_ACCOUNTS
ALICE      2
BOB        2

النتيجة بتقول إن فيه سجلّين مختلفين بيتنافسوا على كل مفتاح مقترح. احسم ملكية الحسابات وسياسة الانتقال قبل فرض عدم التكرار. ما تختارش أول سجل مطابق بشكل عشوائي.

ده اختبار لفكرة تصميم، مش قاعدة عامة لكل أسماء المستخدمين. في نظام متعدد الجهات، ممكن تحتاج مفتاحًا مركبًا يتضمن الجهة. والأسماء الدولية تحتاج سياسة صريحة لـUnicode وقواعد المقارنة وتوحيد النصوص؛ مثال ASCII ده ما بيحسمش القواعد دي. طبّق السياسة المختارة باتساق أثناء إنشاء الحساب والبحث عنه واستعادته وربط الحسابات.

حدّد التعامل مع حالة الحروف صراحةً

لو سياسة الهوية التي راجعتها تقصد الحفاظ على حالة الحروف، ممكن لعملية صفحة تسجيل الدخول التي تحتوي بالفعل على عناصر الاسم وكلمة المرور استخدام المثال التالي:

begin
    apex_authentication.login(
        p_username           => :P9999_USERNAME,
        p_password           => :P9999_PASSWORD,
        p_uppercase_username => false
    );
end;

عدّل أسماء العناصر وراجع Authentication Scheme الفعّالة قبل الاستخدام. مكان الاستدعاء هو عملية تسجيل الدخول؛ ودالة التحقق في الـScheme تقدم قرار صحة بيانات الاعتماد. تغيير المعامل وحده لا ينقل مفاتيح الحسابات القديمة ولا يصلح استعلام بحث يستخدم قواعد متعارضة. ولا تحوّل كلمة المرور لحروف كبيرة أو تحذف مسافاتها لمجرد تطبيق نفس قاعدة اسم المستخدم.

ضع عقدًا مستقلًا لتخزين كلمات المرور

استخدام SHA-512 مرة واحدة، حتى مع دمج بعض بيانات الحساب، لا يساوي تصميمًا حديثًا لتخزين كلمات المرور بخوارزمية قابلة لضبط كلفة الحساب. استخدم مكوّن تحقق مدعومًا يطبق خوارزمية مناسبة مثل Argon2id، مع Salt مستقل لكل كلمة مرور ومعاملات كلفة تمت مراجعتها. احتفظ ببيانات الخوارزمية ومعاملاتها اللازمة للتحقق والترقية. OWASP: تخزين كلمات المرور

حدّد رسالة فشل عامة للمستخدم، وضبطًا لمحاولات الدخول، وسلوك استعادة الحساب، والمصادقة متعددة العوامل المناسبة. احمِ تفاصيل التشخيص ولا تسجّل بيانات الاعتماد في الـLogs. OWASP: إرشادات تسجيل الدخول

قبل الإطلاق، اختبر البيانات الصحيحة، وكلمة المرور الخاطئة، والحساب غير الموجود أو الموقوف، واختلاف حالة الحروف، والمسافات، وتكرار الأسماء بعد توحيدها، وتعطل مكوّن التحقق. راجع قيمة APP_USER الناتجة وربطها بالحساب. الأمثلة السابقة بتوضح التصميم والنتائج المتوقعة، ولا تنفّذ خدمة تحقق متكاملة أو تدّعي تحسنًا مقاسًا في الأداء.

البوست الأصلي على LinkedIn