أمان كلمات المرور
في هذه الصفحة 8 موضوعات
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
نظرة عامة
الموضوعات
- تجزئة كلمات المرور (Password hashing)
- الملح (Salts)
- الخوارزميات التكيفية
- قفل الحساب (Account lockout)
تعلّم أولًا
2 ساعة تدريب (تقدير)
مخرجات التعلم
- Explain why passwords are hashed (not encrypted) and why salts and slow algorithms matter.
- Store passwords with
PasswordEncoder(bcrypt or Argon2) and support future algorithm upgrades. - Implement registration with sensible password rules (length over complexity, breached-password check concept).
- Implement rate limiting or lockout for failed logins and explain the denial-of-service trade-off.
الدروس
المختبر والتمارين
Lab
JNR-037-LAB1 · Registration
Outcomes: 1–4 · Time: ~2 h Implement registration with hashed passwords; throttle after 5 failed logins per account and IP. Acceptance: no plaintext or reversible password anywhere, including logs.
Exercises (assessment: review a flawed registration flow)
| ID | Outcome | Task |
|---|---|---|
| JNR-037-EX01 | 1 | Explain in three sentences why a database stores hashes, not encrypted passwords. |
| JNR-037-EX02 | 1 | Explain what a salt prevents and why MD5 is wrong for passwords. |
| JNR-037-EX03 | 2 | Configure a delegating PasswordEncoder bean and encode and match one password in a test. |
| JNR-037-EX04 | 2 | Describe how you would move from bcrypt to Argon2 without forcing a password reset. |
| JNR-037-EX05 | 3 | Write validation for registration: email format, password length 12 to 128, no composition rules. |
| JNR-037-EX06 | 4 | Implement a failed-login counter and write a test that the sixth attempt gets 429. |
| JNR-037-EX07 | 4 | Review a flawed flow (MD5 hashes, "email not found" message, password in logs) and list every flaw. |
أظهر الحلول
- EX01 Hashes are one-way, so a stolen database does not reveal passwords; encrypted passwords can be decrypted if the key leaks.
- EX02 A salt makes equal passwords hash differently and defeats precomputed tables. MD5 is fast and broken for this use, so guessing is cheap.
- EX03
assertTrue(encoder.matches("pw", encoder.encode("pw")))andassertNotEquals(encode("pw"), encode("pw")). - EX04 Use the delegating encoder with the new default; old
{bcrypt}hashes still match; re-encode on successful login whenupgradeEncodingis true. - EX05
@Email,@Size(min = 12, max = 128)on the password; reject known-breached passwords where a list is available (concept). - EX06 Keep a map of key (account + IP) to counters and a lock-until time; return 429 after five failures; reset on success.
- EX07 MD5 is fast; "email not found" leaks which emails exist; password in logs is plaintext exposure. Fix: delegating encoder, generic message, mask logs.
الاختبار
Outcomes: O1 hashing, salts, slow algorithms · O2 PasswordEncoder and upgrades · O3 registration rules · O4 throttling and lockout.
اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.
الجزء العملي
Seven exercises JNR-037-EX01 to EX07 plus the lab; the flawed-flow review is the assessment. Pass: at least six exercises correct, all flaws in EX07 found, and no plaintext password in the database or logs.
أخطاء شائعة
MD5/SHA-256 for passwords; revealing whether an email exists.
التقييم
Review a flawed registration flow.
الصلة بالمسار الوظيفي
Identity architecture (ARC-017).