انتقل إلى المحتوى
أمين أبوزيد
JNR-037

أمان كلمات المرور

  • 5 درس
  • 2 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

نظرة عامة

الموضوعات

  • تجزئة كلمات المرور (Password hashing)
  • الملح (Salts)
  • الخوارزميات التكيفية
  • قفل الحساب (Account lockout)

تعلّم أولًا

2 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Explain why passwords are hashed (not encrypted) and why salts and slow algorithms matter.
  2. Store passwords with PasswordEncoder (bcrypt or Argon2) and support future algorithm upgrades.
  3. Implement registration with sensible password rules (length over complexity, breached-password check concept).
  4. Implement rate limiting or lockout for failed logins and explain the denial-of-service trade-off.

الدروس

  1. 01كيف تُسرق كلمات المرور
  2. 02التجزئة والتمليح والتجزئة البطيئة
  3. 03PasswordEncoder والترقية
  4. 04القوة الغاشمة (Brute force) والقفل والتقييد (Throttling)
  5. 05عرض عملي: التسجيل مع تجزئة كلمات المرور والتقييد

المختبر والتمارين

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)

IDOutcomeTask
JNR-037-EX011Explain in three sentences why a database stores hashes, not encrypted passwords.
JNR-037-EX021Explain what a salt prevents and why MD5 is wrong for passwords.
JNR-037-EX032Configure a delegating PasswordEncoder bean and encode and match one password in a test.
JNR-037-EX042Describe how you would move from bcrypt to Argon2 without forcing a password reset.
JNR-037-EX053Write validation for registration: email format, password length 12 to 128, no composition rules.
JNR-037-EX064Implement a failed-login counter and write a test that the sixth attempt gets 429.
JNR-037-EX074Review 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"))) and assertNotEquals(encode("pw"), encode("pw")).
  • EX04 Use the delegating encoder with the new default; old {bcrypt} hashes still match; re-encode on successful login when upgradeEncoding is 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.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1Passwords should be stored:O1
  2. 2A salt is:O1
  3. 3Why not SHA-256 for passwords?O1
  4. 4PasswordEncoder.matches(raw, stored):O2
  5. 5The {bcrypt} prefix in a delegating encoder allows:O2
  6. 6A sensible password rule is:O3
  7. 7On failed login, the message should be:O3
  8. 8A permanent lockout after 5 failures risks:O4
  9. 9A good status for too many attempts is:O4
  10. 10Throttling is best keyed by:O4

الجزء العملي

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).

اكتب للبحث في المستويات والمراحل والوحدات والدروس.