Create and validate strong password
Project description
KeyTitan Password Generator and Validator
The provided Python code defines a class called KeyTitan
that serves as a password generator and validator. It generates random passwords that meet certain criteria and validates passwords against specific rules.
KeyTitan Class
The KeyTitan
class has the following methods:
__init__(self, length=12)
This is the constructor method for the KeyTitan
class. It allows you to initialize an instance of the class with an optional password length, with a default length of 12 characters.
generate_password(self)
This method generates a random password based on specified criteria. The criteria for the generated password are as follows:
- The password must be at least 8 characters long.
- It must include at least one uppercase letter, one lowercase letter, one digit, and one special character.
- The remaining characters are randomly chosen from all character sets.
- The order of characters in the password is randomized.
If the password length is less than 8, a ValueError
is raised. Otherwise, a password is generated and returned.
validate_password(self, password)
This method validates a given password against specific criteria, including:
- The password must be at least 8 characters long.
- It must include at least one uppercase letter, one lowercase letter, one digit, and one special character.
If the password meets these criteria, the method returns True
. If not, it prints error messages for the specific criteria that the password does not meet and returns False
.
Example Usage
The code provides an example of how to use the KeyTitan
class:
- An instance of the
KeyTitan
class is created with a specified password length of 10 characters. - A random password is generated using the
generate_password
method and printed to the console. - The generated password is then validated using the
validate_password
method against the same criteria. If the password is valid, it prints "Password is valid." Otherwise, it prints error messages for the criteria that are not met.
Summary
The KeyTitan
class provides a simple and customizable way to generate and validate passwords based on specific criteria. It ensures that generated passwords meet security standards by requiring a minimum length and including a mix of character types. The code can be easily integrated into applications or scripts that require secure password generation and validation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.