Home > Learning, Lesson, Projects/Experiments, Python > Python: Password Generator

Python: Password Generator



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




Follow me on Twitter..




By: Ali Radwani




  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: