Archive
Archive for January 1, 2021
Python: Password Generator
January 1, 2021
Leave a comment
Learning : Python Project
Subject: Password Generator
In this function we will use the string library to select a random X numbers of letters as a Password length and print it on the screen.
First: We create a list of letters type l_type that hold the following: lowercase, uppercase, digits, punctuation and we will use the (random.choice) to select from the list.Then we will call the ‘password Generator’ pass_generator function torandomly select a letter based on the selected type, we will do so for a X time (X is the length of the password). In this project we will print the password on the screen, in real-life we can send the password via email or SMS. Here is the Code ..
# Password Generator Function
"""
Project: Python Password Generator
By: Ali Radwani
Date: Des-2020
This function will use the string library to select a random X numbers of letters as a Password and print it on the screen.
We create a list of letter type l_type that hold the following lowercase, uppercase, digits, punctuation and we will
use the (random.choice) to select from the list, then we will call the 'password Generator' pass_generator function to
randomly select a letter, we will do so for a X time (X is the length of the password). In this project we will print
the password on the screen, in real-life we can send the password via email or SMS.
"""
import random, string
l_type = ["lowercase","uppercase","digits","punctuation"]
the_password =[]
def pass_generator(lt) :
if lt =="lowercase":
the_password.append(random.choice(string.ascii_lowercase))
elif lt =="uppercase" :
the_password.append(random.choice(string.ascii_uppercase))
elif lt =="digits" :
the_password.append(random.choice(string.digits))
elif lt =="punctuation":
the_password.append(random.choice(string.punctuation))
return the_password
pass_length = int(input("\n Enter the password Length: > "))
while len(the_password) < pass_length:
pass_generator(random.choice(l_type))
print("\n The New Generated Password is: ","".join(the_password))
To Download my Python code (.py) files Click-Here
By: Ali Radwani
Follow me on Twitter..

