API Reference
This page contains detailed API documentation for the PassCrypt package.
CryptoHandler
- class pypasscrypt.passcrypt.CryptoHandler[source]
Bases:
object
A class to handle encryption and decryption of data using Fernet symmetric encryption.
- static get_cipher(input_string: str) Fernet [source]
Generate a Fernet cipher object using the input string as the key.
- Parameters:
input_string – The input string to generate the key.
- Returns:
A Fernet cipher object.
- static encrypt(data: Dict[str, Any], password: str) bytes [source]
Encrypt the given data using the provided password.
- Parameters:
data – The data to encrypt, as a dictionary.
password – The password to use for encryption.
- Returns:
Encrypted data as bytes.
- static decrypt(encrypted_data: bytes, password: str) Dict[str, Any] [source]
Decrypt the given encrypted data using the provided password.
- Parameters:
encrypted_data – The data to decrypt, as bytes.
password – The password to use for decryption.
- Returns:
The decrypted data as a dictionary.
- Raises:
Exception if decryption fails.
PasswordGenerator
- class pypasscrypt.passcrypt.PasswordGenerator[source]
Bases:
object
A class to generate passwords based on given context and constraints.
- static is_valid_context(s: str) bool [source]
Check if the string matches any context filter.
- Parameters:
s – The string to check.
- Returns:
True if the string does not match any context filter, False otherwise.
- static break_context(s: str) List[str] [source]
Break the context into smaller parts based on non-word characters.
- Parameters:
s – The string to break.
- Returns:
A list of valid context parts.
- static generate_password(context: List[str], length: int = 15, upper_case: bool = True, lower_case: bool = True, numbers: bool = True, symbols: bool = True, exclude_similar: bool = False) str [source]
Generate a password based on the given parameters and context.
- Parameters:
context – The list of context strings.
length – The desired length of the password.
upper_case – Whether to include uppercase letters.
lower_case – Whether to include lowercase letters.
numbers – Whether to include numbers.
symbols – Whether to include symbols.
exclude_similar – Whether to exclude similar characters.
- Returns:
The generated password.
- Raises:
ValueError – If the length is not a positive number or no character types are allowed.
Storage
- class pypasscrypt.passcrypt.Storage(password: str, new: bool)[source]
Bases:
object
A class to manage storage of passwords securely.
- __init__(password: str, new: bool) None [source]
Initialize the Storage object.
- Parameters:
password – The master password for the storage.
new – Whether to create a new storage file or load an existing one.
- Returns:
None
- validate_secret(secret: str) bool [source]
Validate the secret against the master password hash.
- Parameters:
secret – The secret to validate.
- Returns:
True if the secret is valid, False otherwise.
- add_password(site: str, username: str, password: str) None [source]
Add a password to the storage.
- Parameters:
site – The site for which the password is being added.
username – The username associated with the password.
password – The password to store.
- Returns:
None
- remove_password(site: str, username: str) None [source]
Remove a password from the storage.
- Parameters:
site – The site for which the password is being removed.
username – The username associated with the password.
- Returns:
None
- edit_password(site: str, username: str, new_site: str, new_username: str, new_password: str) None [source]
Edit a password in the storage.
- Parameters:
site – The site for which the password is being edited.
username – The username associated with the password.
new_site – The new site for the password.
new_username – The new username associated with the password.
new_password – The new password to store.
- Returns:
None
- list_all() List[Tuple[str, str]] [source]
List all passwords in the storage.
- Returns:
A list of all passwords in the storage.
- get_all_sites() List[str] [source]
Get all sites in the storage.
- Returns:
A list of all sites in the storage.
- get_all_usernames() List[str] [source]
Get all usernames for a site in the storage.
- Returns:
A list of all usernames in the storage.
- get_username_for_site(site: str) List[str] [source]
Get the username for a site in the storage.
- Parameters:
site – The site for which to retrieve the username.
- Returns:
A list of usernames for the site.
- get_password_for_site(site: str, username: str) str | None [source]
Get the password for a site in the storage.
- Parameters:
site – The site for which to retrieve the password.
username – The username associated with the password.
- Returns:
The password for the site, or None if not found.
- site_exist(site: str) bool [source]
Check if a site exists in the storage.
- Parameters:
site – The site to check.
- Returns:
True if the site exists, False otherwise.
- username_exist(site: str, username: str) bool [source]
Check if a username exists for a site in the storage.
- Parameters:
site – The site to check.
username – The username to check.
- Returns:
True if the username exists, False otherwise.
- change_master_password(new_password: str) None [source]
Change the master password for the storage.
- Parameters:
new_password – The new master password.
- Returns:
None
- export_storage(secret: str) str [source]
Export the storage data.
- Parameters:
secret – The secret to encrypt the storage data.
- Returns:
The encrypted storage data.
- import_storage(secret: str, file_path: str, confirm: Callable) bool [source]
Import the storage data.
- Parameters:
secret – The secret to decrypt the storage data.
file_path – The path to the file to import.
confirm – The confirmation function.
- Returns:
True if the import is successful, False otherwise.
UserInterface
- class pypasscrypt.passcrypt.UserInterface[source]
Bases:
object
A class to handle the user interface for the Password Manager.
- add_password()
Add a password to the storage.
- remove_password()
Remove a password from the storage.
- edit_password()
Edit a password in the storage.
- list_all()
List all passwords in the storage.
- settings()
Display the settings menu.
- clear_logs()
Clear the logs.
- remove_pc()
Remove the PassCrypt storage file.
- export_logs()
Export the PassCrypt logs to a file.
- export_pc()
Export the PassCrypt storage to a file.
- import_pc()
Import a PassCrypt storage from a file.
- clear_all_data()
Clear all passwords from the storage.
- change_master_password()
Change the master password for the storage.
- new_page(title: str, subtitle: str, message: str = '') None [source]
Print a new page separator.
- Parameters:
title – The title of the page.
subtitle – The subtitle of the page.
message – The message to show in panel.
- Returns:
None
- create_table(title: str, headers: List[str], data: List[List[str]]) None [source]
Create a table with the given title, headers, and data.
- Parameters:
title – The title of the table.
headers – The headers of the table.
data – The data for the table.
- Returns:
None
- get_password(site: str, username: str) str [source]
Get a password from the user or generate one if not provided.
- Parameters:
site – The site for which the password is being generated.
username – The username associated with the password.
- Returns:
The generated or provided password.
- static master_validation(password: str) bool [source]
Validate the master password.
- Parameters:
password – The password to validate.
- Returns:
True if the password is valid, False otherwise.
- get_master_password(message: str) str [source]
Get the master password from the user.
- Parameters:
message – The message to display to the user.
- Returns:
The master password provided by the user.
- static get_selection(message: str, choices: List[str], default: Any = None, skip_message: str = '') str [source]
Get a selection from the user.
- Parameters:
message – The message to display to the user.
choices – The choices to display to the user.
default – The default choice.
skip_message – The message to display for skipping the selection.
- Returns:
The selected choice.
- static get_input(message: str, default: Any = None) str [source]
Get input from the user.
- Parameters:
message – The message to display to the user.
default – The default input.
- Returns:
The input provided by the user.
- ui_input(mode: Literal['INPUT', 'SELECTION', 'BOTH', 'PASSWORD', 'MASTER_PASSWORD', 'CONFIRM', 'FILE'], selection_message: str | None = None, choices: List[str] | None = None, input_message: str | None = None, skip_message: str = '', default: Any = '', site: str | None = None, username: str | None = None) str [source]
Get input from the user based on the specified mode.
- Parameters:
mode – The mode to use for input.
selection_message – The message for selection mode.
choices – The choices for selection mode.
input_message – The message for input mode.
skip_message – The message for skipping the selection.
default – The default input.
site – The site for password mode.
username – The username for password mode.
- Returns:
The input provided by the user.
- show_error(message: str) None [source]
Display an error message to the user.
- Parameters:
message – The error message to display.
- Returns:
None
- show_success(message: str) None [source]
Display a success message to the user.
- Parameters:
message – The success message to display.
- Returns:
None
- show_info(message: str) None [source]
Display an informational message to the user.
- Parameters:
message – The informational message to display.
- Returns:
None
- show_warning(message: str) None [source]
Display a warning message to the user.
- Parameters:
message – The warning message to display.
- Returns:
None
- show_greet_panel(title: str, subtitle: str, message: str) None [source]
Display a warning panel to the user.
- Parameters:
title – The title of the panel.
subtitle – The subtitle of the panel.
message – The warning message to display.
- Returns:
None
- show_warning_panel(title: str, subtitle: str, message: str) None [source]
Display a warning panel to the user.
- Parameters:
title – The title of the panel.
subtitle – The subtitle of the panel.
message – The warning message to display.
- Returns:
None
- show_error_panel(title: str, subtitle: str, message: str) None [source]
Display an error panel to the user.
- Parameters:
title – The title of the panel.
subtitle – The subtitle of the panel.
message – The error message to display.
- Returns:
None
PasswordManager
- class pypasscrypt.passcrypt.PasswordManager[source]
Bases:
object
A class to manage the Password Manager application.
- init_pm() Tuple[bool, Storage | None] [source]
Initialize the Password Manager
- Returns:
A tuple containing the status and the storage object.
- generate_master()[source]
Generate the master password for the Password Manager.
- Returns:
The generated master password.
- login() Tuple[bool, Storage | None] [source]
Login to access the password manager
- Returns:
A tuple containing the status and the storage object.
Display the main menu of the Password Manager.
- Returns:
None
Constants
- pypasscrypt.passcrypt.SIMILAR_CHARS
Dictionary of characters that are visually similar and can be easily confused.
Key-value pairs where the key is a character and the value is a string of characters that look similar to the key.
- pypasscrypt.passcrypt.CONTEXT_FILTER
List of context filters to exclude from password generation.
Contains strings that are commonly used in passwords and should be avoided to ensure the generated passwords are secure.
- pypasscrypt.passcrypt.APPLICATION_NAME
The name of the application.
- pypasscrypt.passcrypt.LOCATION
The location to store the application data.
- pypasscrypt.passcrypt.DIRECTORY
The directory to store the application data.
- pypasscrypt.passcrypt.FILENAME
The name of the storage file.
- pypasscrypt.passcrypt.EXTENSION
The extension of the storage file.
- pypasscrypt.passcrypt.DOWNLOADS
The default downloads directory.
- pypasscrypt.passcrypt.EXPORT_DIRECTORY
The directory to store exported data.
- pypasscrypt.passcrypt.PATHS
Dictionary of paths used by the application.
Contains key-value pairs where the key is a description of the path and the value is the actual path used by the application.
Functions
- pypasscrypt.passcrypt.main()[source]
Run the Password Manager application.
- Returns:
None