Syllabus :

Introduction :

I haven’t been putting out enough content on my blog due to my somewhat busy lifestyle. Today’s blog post is on a python password generator that uses lower, upper, numbers and special ascii characters. I am using the string package to generate the characters used for the password and the random package to randomize the characters. The reason why I created a password generator is because I live on a CLI and didn’t find one that fit what I wanted; So I hacked one together. The default password length is 15 but you can change this by changing the variable “pw_length” to your pleasing. This generator should work with just about any system because both the random and string package are included by default with python.

Python Password Generator

Below is the python password generator, :

import random
import string

characters = string.ascii_letters + string.digits + string.punctuation
pw_length = 15
mypw = ""

for i in range(pw_length):
    next_index = random.randrange(len(characters))
    mypw = mypw + characters[next_index]

print('Your new password: ' + mypw)

Permenant alias to current user :

If you are like me who hates typing long repetitive commands you will want to learn how to make permanent aliases. To create a permanent alias you need to add a regular standard alias into ~/.bash_profile. If you named your python script and its located in ~/, you can add your permanent alias by typing this :

echo "python ~/" >> ~/.bash_profile

This will allow it to be run from anywhere in the CLI.

Closing :

Creating the script has been really cool and very hacky but this password generator outputs password that are not meant to be remembered, so my next password generator project will be to generate 7 words using EFF large wordlist to create a dice-generated passphrase instead of globby goo. Thank you and hope you enjoy this project.