PasswordPolicy class

Password validation policy

Configure password requirements for registration.

const PasswordPolicy policy = PasswordPolicy(
  minLength: 8,
  requireUppercase: true,
  requireLowercase: true,
  requireNumber: true,
  requireSpecialChar: true,
);

String? error = policy.validate(password);

Constructors

PasswordPolicy({int minLength = 6, int maxLength = 128, bool requireUppercase = false, bool requireLowercase = false, bool requireNumber = false, bool requireSpecialChar = false})
const

Properties

description String
Get a human-readable description of the policy
no setter
hashCode int
The hash code for this object.
no setterinherited
maxLength int
Maximum password length
final
minLength int
Minimum password length
final
requireLowercase bool
Require at least one lowercase letter
final
requireNumber bool
Require at least one number
final
requireSpecialChar bool
Require at least one special character
final
requireUppercase bool
Require at least one uppercase letter
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

isValid(String password) bool
Check if a password is valid
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
validate(String password) String?
Validate a password against this policy

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

medium → const PasswordPolicy
Medium password policy preset
strong → const PasswordPolicy
Strong password policy preset
weak → const PasswordPolicy
Weak password policy preset (just length)