Skip to content

Latest commit

 

History

History
205 lines (151 loc) · 6.35 KB

File metadata and controls

205 lines (151 loc) · 6.35 KB

Password Strength Meter Feature

Overview

This feature implements a comprehensive password strength meter with real-time feedback, following NIST SP 800-63B password guidelines. It enhances security by helping users create strong, secure passwords during signup.

Features

1. Real-time Password Strength Indicator

  • Visual Progress Bar: Shows password strength as a percentage (0-100%)
  • Color-coded Feedback:
    • 🔴 Red (0-20%): Weak
    • 🟠 Orange (21-40%): Fair
    • 🟡 Yellow (41-60%): Good
    • 🟢 Light Green (61-80%): Strong
    • 💚 Green (81-100%): Very Strong

2. NIST Password Guidelines Enforcement

Following NIST Special Publication 800-63B:

  • ✅ Minimum 8 characters (upgraded from 6)
  • ✅ Maximum 64 characters support
  • ✅ Blocks common passwords (top 100 weak passwords)
  • ✅ Prevents sequential characters (e.g., "12345", "abcdef")
  • ✅ Prevents repeated characters (e.g., "aaaa", "1111")
  • ✅ Detects keyboard patterns (e.g., "qwerty", "asdfgh")

3. Interactive Requirements Checklist

Shows real-time status of password requirements:

  • ✅ At least 8 characters long
  • ✅ Contains uppercase letter (A-Z)
  • ✅ Contains lowercase letter (a-z)
  • ✅ Contains number (0-9)
  • ✅ Contains special character (!@#$%^&*)
  • ✅ Not a common password
  • ✅ No sequential characters
  • ✅ No repeated patterns

4. Smart Feedback System

Provides contextual tips for improving weak passwords:

  • Suggests adding missing character types
  • Warns about common passwords
  • Identifies patterns to avoid
  • Encourages stronger complexity

Implementation Details

Files Modified/Created

  1. auth/password_validator.py (NEW)

    • Core password validation logic
    • Strength calculation algorithm
    • NIST guidelines implementation
    • Pattern detection utilities
  2. components/login_page.py (MODIFIED)

    • Updated validate_password() to use new validator
    • Added render_password_strength_meter() function
    • Integrated strength meter into signup form
    • Added CSS styling for visual components
  3. auth/auth_utils.py (MODIFIED)

    • Import PasswordValidator class
    • Updated validation flow
  4. test_password_validator.py (NEW)

    • Comprehensive unit tests (26 test cases)
    • 100% test coverage for validator
    • Tests all NIST requirements

Usage

For Users

When signing up, users will see:

  1. Password Input Field: Type password
  2. Strength Meter: Visual bar showing strength percentage
  3. Strength Label: Text indicator (Weak/Fair/Good/Strong/Very Strong)
  4. Requirements Checklist: Live updates showing which requirements are met
  5. Helpful Tips: Suggestions for improving weak passwords

For Developers

from auth.password_validator import PasswordValidator

# Validate a password
is_valid, message = PasswordValidator.validate_password("MyPassword123!")
print(f"Valid: {is_valid}, Message: {message}")

# Get detailed strength analysis
strength_data = PasswordValidator.calculate_strength("MyPassword123!")
print(f"Score: {strength_data['score']}")
print(f"Strength: {strength_data['strength']}")
print(f"Checks: {strength_data['checks']}")
print(f"Feedback: {strength_data['feedback']}")

Security Benefits

  1. Prevents Weak Passwords: Blocks common, sequential, and pattern-based passwords
  2. NIST Compliance: Follows industry-standard security guidelines
  3. User Education: Teaches users about password security
  4. Reduced Account Compromise: Stronger passwords reduce brute-force attack success
  5. Better User Experience: Real-time feedback helps users create strong passwords without frustration

Testing

Run the test suite:

# Run all password validator tests
python -m pytest test_password_validator.py -v

# Run with coverage report
python -m pytest test_password_validator.py --cov=auth.password_validator --cov-report=html

Test Results: 26/26 tests passing ✅

Password Strength Scoring Algorithm

Score is calculated based on:

Length (30 points max)

  • 8+ characters: 15 points
  • 12+ characters: +10 points
  • 16+ characters: +5 points

Character Variety (40 points max)

  • Uppercase letters: 10 points
  • Lowercase letters: 10 points
  • Numbers: 10 points
  • Special characters: 10 points

Pattern Avoidance (30 points max)

  • Not a common password: 10 points
  • No sequential characters: 10 points
  • No repeated characters: 5 points
  • No keyboard patterns: 5 points

Total: 100 points maximum

Common Passwords Blocked

The validator blocks 100+ common passwords including:

  • password, 123456, qwerty, abc123
  • letmein, welcome, admin, hello
  • And many more...

Examples

❌ Weak Passwords (Rejected)

  • password - Common password
  • 12345678 - Sequential numbers
  • qwerty123 - Keyboard pattern
  • aaaaa123 - Repeated characters
  • short - Too short (< 8 characters)

✅ Strong Passwords (Accepted)

  • MyStr0ng!Pass - 13 chars, mixed case, numbers, special
  • S3cur3P@ssw0rd - 14 chars, complex, no patterns
  • C0mpl3x!tyRul3s - 15 chars, all requirements met
  • Tr€€H0us3#2024 - Unique, complex, memorable

Accessibility

  • Color-blind friendly: Uses icons (✅/❌) in addition to colors
  • Screen reader compatible: Semantic HTML with aria-labels
  • Keyboard navigable: All interactive elements accessible via keyboard
  • Mobile responsive: Adapts to different screen sizes

Future Enhancements

Potential additions for future versions:

  • Password breach checking (Have I Been Pwned API)
  • Password history (prevent reuse)
  • Custom dictionary support for organization-specific blocked words
  • Strength estimation using zxcvbn library
  • Multi-language support for feedback messages
  • Password generator with strong defaults

References

License

This feature is part of the TalkHeal project and follows the same MIT License.

Contributors

  • Initial implementation: Part of issue #429 enhancement
  • NIST guidelines compliance
  • Comprehensive testing suite
  • User-friendly UI/UX design

For questions or improvements, please open an issue or submit a pull request.