Overview
LocalRegex provides a secure password generation utility that creates random passwords containing uppercase letters, lowercase letters, numbers, and special characters.Method signature
Parameters
The desired length of the generated password. Must be a positive integer.
Character sets
The generated password includes characters from all of the following sets:- Lowercase letters:
a-z - Uppercase letters:
A-Z - Numbers:
0-9 - Special characters:
!@#$%^&*()-_=+[]{}|;:",.<>?/~`
The password generator uses
Random.secure() to ensure cryptographically secure random number generation.Basic usage
Generate default password
Generate a 12-character password (default length):Generate custom length password
Generate a password with a specific length:Use cases
User registration
Generate temporary passwords for new user accounts
Password reset
Create secure temporary passwords when users request password resets
API keys
Generate random API keys or tokens for authentication
Test data
Create test passwords for development and testing environments
Password strength
The generated passwords are designed to be strong and secure:Character diversity
Character diversity
Each password is guaranteed to contain a mix of uppercase, lowercase, numbers, and special characters, making them resistant to dictionary attacks.
Cryptographic randomness
Cryptographic randomness
The
Random.secure() generator provides cryptographically strong random numbers suitable for security-sensitive applications.Customizable length
Customizable length
Longer passwords provide exponentially more possible combinations, increasing security. The default 12 characters provides good security for most use cases.
Example: User registration flow
Validation
To validate if a password meets strength requirements, use theisPassword() method: