Github Repository
Github Project
This application is a project to fulfill assignment requirements for the coder academy web development course. It is a terminal application that can be run directly from the command line or with the use of the bash scripts that are contained within this repo.
PyPassGen is a password generator that generates passwords based on set of user provided arguments and has the ability to store and encrypt / decrypt passwords to a computer. The application also uses argparse as a way to receive command line options and arguments to adjust the output. Argparse help documentation has also been written so that a help menu can be displayed by using the '-h' argument. These explanations are also found in the command line arguments heading below.
The encryption and decryption are handled through the Cryptography library which generates a Fernet key. The storage and use of such admittedly is not secure however more secure methods are outside the scope of this project.
The style guide used for this project is 'Google Python Style Guide' which can be found here: https://google.github.io/styleguide/pyguide.html. The code follows this style guide as rigidly as possibly, using black as a recommended code formatter and Google's pylintrc for running a linter over the code.
The application consists of 3 main features:
The password generation operates by checking if expressions are used (see below), and checking the flags / options that are passed through as CLI options and arguments. It then generates the password according to these constructors. An explanation of these arguments can be found under the 'Command Line Arguments' heading below. In summation, the user can decide the amount of characters present in the password, the amount of passwords to generate, and what series of characters are present in the password. These are than displayed to the terminal and a flag can be used to copy the entire list immediately to the clipboard if the user would prefer to store these elsewhere.
There is an option available for the user to create a custom expression to dictate the composition of the generated password. This function will provide a brief description to the user of how an expression is composed and than request for the user to create one of these expressions. The input is checked for invalid characters, and if invalid, will prompt the user to provide another one until the expression matches an expected input.
The list of possible characters to use can be found below:
The function will accept both upper and lowercase characters as it forces the characters to lower on input. Using the above characters, a couple of examples of this are below:
Expression: llluuunnnsss
Generated Password: vkxDYS221['#
Expression: uuuuunnnnn
Generated Password: TTGTO03879
Each letter represents a random character from that character series.
Once passwords have been generated, the application will than prompt the user on whether they want to save the password or not. If the user confirms this is the case, the application will than check if a 'passwords.txt' file already exists at the current folder destination. If it doesn't, it will create one automatically. If it does, the application will provide to ask the user whether they would like to append the new passwords to the list, or they would like to overwrite the existing passwords.txt. If the overwrite option is chosen and the 'force' flag isn't used, than the application will request confirmation from the user again, mentioning that this will lose any passwords in the current file.
Once the save has been completed, the application will ask whether the user would like to encrypt the saved passwords. If confirmed, the program will first check whether a 'key.txt' file exists in the current directory. If so, it will assume that the 'key.txt' file contains a Fernet key generated by the cryptography library and use that for encryption. If the file doesn't exist, the application will generate a new key and notify the user that it has been created, it will than open the passwords file, encrypt the contents, and overwrite the existing file using the token as a binary object as required for the encryption methodology.
The program can also be used to view or copy passwords from existing 'passwords.txt' files, bearing in mind that if they are encrypted, the 'key.txt' file is required in the current directory. If they are encrypted passwords but the 'key.txt' file is not present, the application will just print out the encrypted string series. A copy flag can also be used with the view functionality to automatically copy all the passwords present in the file after the decryption has taken place.
A github project was created to manage the implementation plan and track key tasks throughout the development of this application. The project can be found at this link: https://github.com/users/MiloMT/projects/1.
This project was updated consistently throughout development to manage the variety of tasks associated with the application.
Table Initialization: Part 1 Table Initialization: Part 2 Initial Roadmap Midway through Password Generation End of Password Generation Inclusion of extra project fields for docs / scripts Updates dependent on task status Getting through password generation Nearly finished expression generation Getting through encryption functionality with checklist and comments Updated Roadmap Starting on documentation Extra bash scripts added as required Managing Issues through Github Interface Midway through bash scripts Bashscripts Finished Pytest Issues added Finalising all but documentation Final comments before first submission
All used packages are compatible with all major operating systems (Windows, MacOS, Linux), so this application can be used across any of these OS's. There are multiple scripts contained within the 'script' folder that can be used for installation and basic use cases of the application (windows specific), or the application can be run directly via the command line. Please note that in order to run the application, you must have Python >= 3.10 version installed for the cryptography library and the match case functionality used in the code.
The only base requirement for running the application is having Python version >= 3.10 installed on the computer. You can download and install the latest python installation directly through the Python homepage: https://www.python.org/
As for hardware requirements, you need to ensure that your system has the minimum OS versions as below:
As mentioned above, a Python version >= 3.10 must be installed in order to run the application or the below scripts. There is a beginner guide for installer Python available at the link below:
https://wiki.python.org/moin/BeginnersGuide/Download
You can also find the latest Python downloads available at this link:
https://www.python.org/downloads/
Python is available for any major operating system, so just ensure that you are using the relevant installation instructions for your operating system.
There are two external libraries used within the application. These can be found below along with their documentation and installation instructions if you would like to manually install them:
The installation scripts discussed in the next section can take care of the dependency installation for you.
There are two different installation scripts. One that installs the application dependencies within a virtual environment and one that installs the dependencies within the local environment. Once the installation scripts have been run, than there are three variations of example use cases that can be run depending on the installed environment. One for a basic password generation, one to run the application in expression mode, and than lastly one to run the application in view mode.
The below assumes you already have Python version >= 3.10 installed to your computer. If you don't, please refer to the above under Python Installation.
Firstly, you will need to ensure that you have the source code downloaded to a location on your computer. You can do this in one of two ways, you can either download a ZIP package containing all the relevant information through the menu below from the github repository (https://github.com/MiloMT/PyPassGen):
Once downloaded, you will need to uncompress the zip package using the software of your choosing to a location that you would like to store the application. Make note of this location, as you will need it shortly.
Or if you are familiar with git, you can clone the repository to a chosen local destination. The instructions for cloning a repository can be found in this link: https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository
Installing the dependencies can be done in one of two ways, either using the bash scripts provided with the repository, or by installing them through python manually through pip.
PIP
In order to install the required packages through PIP, you will need to first navigate to the repository in your terminal, then run the below command.
pip install -r requirements.txt
PIP will take care of the installation procedures involved with these packages. If you are using a virtual environment, you will need to make sure that the virtual environment is activated prior to running the pip commands.
If you have any issues with the above, you can refer to the official Python installing packages guide through this link: https://packaging.python.org/en/latest/tutorials/installing-packages/
Bash Scripts
There are two different installation bash scripts contained with the 'scripts' folder of the repository. In order to run them, you will need to open your terminal, navigate to the folder that contains these bash scripts, and than run them by entering the below commands:
For installing to your local environment
./std_install.sh
For installing to a virtual environment
./venv_install.sh
That should be all there is to it! You can now use the program. Refer to the below for run instructions.
The application can either be run standalone or through the bash scripts that have been provided. Ensure that the installation steps have been fully completed prior to running the application.
In order to run the application through the python file directly, you can do so by first navigating to the repository via your terminal, and than running the below command:
python3 main.py
By just running the python file as above, it will run the application using a series of default arguments. This will result in a single password being generated, composed of lower-case letters at 10 characters long:
Afterwards, the application will prompt whether you would like to save the password, and if you have saved, whether you would like to encrypt those passwords.
The application can run in multiple modes and with multiple options depending on how you would like to operate. Some of the most common ones are:
View Mode
python3 main.py --view
This allows you to view previously saved passwords in a passwords.txt file.
Expression Mode
python3 main.py -e
This allows you to create an expression for password generation. Please refer to the feature list above for further explanation.
Password Manipulation
python3 main.py 20 5 -uns
You can also manipulate the length of passwords, the amount of passwords generated, and the type of characters used in the passwords. The first integer will refer to the length of each password, the second integer refers to the amount of passwords generated, and lastly the options '-u', '-n', '-s', or in this case, '-uns', refer to the type of characters using in the passwords. In this case [U]ppercase, [N]umbers, and [S]pecial characters.
For further arguments and options, you can refer to the command line arguments section below, or the in-app help guide through the below command.
python3 main.py -h
There are also scripts available to run the application in a more simplified version. You can run the script through by the below command when inside the 'scripts' folder in your terminal:
For running when using a local environment
./std_run.sh
For running when using a virtual environment
./venv_run.sh
The bash scripts can also run with a few variations. To run the application in standard mode, you can use the below commands. These will generate 5 passwords at 10 characters each.
For running when using a local environment
./std_run.sh std
For running when using a virtual environment
./venv_run.sh std
To run the application in view mode, you can use the below commands. This will just view previously saved passwords:
For running when using a local environment
./std_run.sh view
For running when using a virtual environment
./venv_run.sh view
To run the application in expression mode, you can use the below commands. This will run the app and prompt the user to create an expression for the password generation. Once received, it will generate 5 passwords at 10 characters each using that expression:
For running when using a local environment
./std_run.sh exp
For running when using a virtual environment
./venv_run.sh exp
usage: main.py [-h] [-c] [-e] [-f] [-n] [-s] [-u] [--view] [Num_of_Chars] [Num_of_Passwords]
Generates a password or series of passwords given a set of parameters
Num_of_Chars Optionally enter a number of characters in password. (default: 10)
Num_of_Passwords Optionally create a number of passwords. (default: 1)
-h, --help : show this help message and exit
-c, --copy : Copies the password to the clipboard once generated or viewed
-e, --expression : Lets the generator know that you want to create an expression to control the password generation
-f, --force : Forces overwrite so app ignores overwrite confirmation
-n, --number : Adds numbers to password generation
-s, --special : Adds special characters to password generation
-u, --upper : Adds uppercase letters to password generation
--view : Instead of generating passwords, prints out passwords to terminal