Project Level 1: Beginner
This project is designed for beginner learners who are still learning and practicing Python fundamentals.
Project Description
Create a command-line app that generates secure random passwords based on user preferences. The user can specify the password length and whether to include uppercase letters, numbers, and special characters. This project focuses on randomness, string operations, and user input validation.
Expected Output
The program starts by asking the user a few questions, such as the desired password length, and if there have to be any uppercase letters, numbers, or special characters in the password. Depending on the user's answers, the program generates a password and prints it out, as shown in the screenshot above.
Learning Benefits
You will practice working with randomness, string operations, and user input validation. This project helps you understand how to build customizable tools for practical use.
Prerequisites
Required Libraries: random, string
No need to install any library since random is a standard library.
Required Files: No external files are needed.
IDE: You can use any IDE on your computer to code the project.
Danger Zone
Once you code the project, compare it with our solution below:
import random as rd
import string as st
print('Welcome to the password generator !')
x1=int(input('Input the length of the pwd(minimum 6'))
x=input('Include upper case letters (yes/no)')
y=input('Include numbers (yes/no)')
z=input('Include special characters(yes/no)')
match(x,y,z):
case('yes','yes','yes'):
character=st.ascii_letters+st.digits+st.punctuation+st.ascii_uppercase
pwd=''.join(rd.choice(character) for i in range(x1) )
print(pwd)
case('no','yes','yes'):
character=st.ascii_lowercase+st.digits+st.punctuation
pwd=''.join(rd.choice(character) for i in range(x1) )
print(pwd)
case('yes','no','yes'):
character = st.ascii_letters + st.ascii_uppercase + st.punctuation
pwd = ''.join(rd.choice(character) for i in range(x1))
print(pwd)
case('yes','yes','no'):
character = st.ascii_letters + st.ascii_uppercase + st.digits
pwd = ''.join(rd.choice(character) for i in range(x1))
print(pwd)
case('no','no','yes'):
character = st.ascii_lowercase + st.punctuation
pwd = ''.join(rd.choice(character) for i in range(x1))
print(pwd)
case ('yes', 'no', 'no'):
character = st.ascii_uppercase + st.ascii_letters
pwd = ''.join(rd.choice(character) for i in range(x1))
print(pwd)