This module implements a password strength estimator that assesses password strength based on multiple factors including length, character diversity, repetition, sequential patterns, and leet substitutions.
It provides a comprehensive analysis of password strength and offers feedback for improvement.
Optionally, you can feed the estimator a list of common passwords or breached passwords to further penalize passwords that are known to be weak.
This module has no external dependencies and can be easily integrated into any Nim project that requires password strength evaluation, such as user registration or password change forms.
Types
PasswordStrength = enum Weak, Medium, Strong
- Represents the strength of a password.
PasswordStrengthReason = enum TooShort, NotEnoughVariety, TooPredictable, SimilarToCommon, GoodComplexity
- Reasons for password strength classification, useful for user feedback.
PasswordStrengthResult = object strength*: PasswordStrength ## A float score representing the calculated strength ## of the password. Higher is stronger. score*: float32 ## A human-readable reason explaining the strength ## assessment, useful for feedback to users. reason*: PasswordStrengthReason
- The result of a password strength evaluation, including the strength category,
Procs
proc passwordStrength(password: string): PasswordStrengthResult {....raises: [], tags: [], forbids: [].}
- Evaluates the strength of a password based on multiple factors including length, character diversity, repetition, sequential patterns, and leet substitutions. Provides a strength category, score, and feedback reason.
proc passwordStrength(password: string; commonPasswords: seq[string]): PasswordStrengthResult {. ...raises: [], tags: [], forbids: [].}
- Complexity score + optional fuzzy penalty against provided common passwords.
proc passwordStrength(password: string; dict: PasswordStrengthDictionary): PasswordStrengthResult {. ...raises: [KeyError], tags: [], forbids: [].}
-
Complexity score + optional fuzzy penalty using a prepared dictionary.
This allows you to further penalize passwords that are similar to known weak passwords, while still providing a complexity-based strength assessment.