Password generator using Python
Password
generator using Python
1. Introduction
In today’s digital world a
strong password is the first line of defense against cyber threat is the strong
password. One of the leading causes of data breach is the weak and reused
password.
In this article, we’ll build
a password generator using Python, a simple yet effective Cybersecurity project
ideal for beginners. It utilizes the python libraries such as random and string
which allows in generating random number, alphabet and special characters.
2. Project Objective
It is the short and the
weekend project which can be completed within hours which helps you to brush-up
your python skills and understanding of the language. The password generate
takes user input to determine the length of the password and if the given
length is less than the appropriate length then the generator reply with the “The length must be equal or greater than 8”
and if the user give appropriate length for the generator it will proceed
with the generation of the password.
3. Understanding the Logic
Libraries used:
1.
Random : It is used to generate random selection
2.
String : It is used to access sets of characters like
the letter, digit and punctuations.
Ø string.ascii_letters
Ø string.digital
Ø string.puntuation
Conditional Statement
1. if
2. else
4. Code Walkthrough
import random
import string
len = int(input("Enter
the length password: ")) #taking
user input from the user
if len >=8: #checking if
the given user input satisfies the length
def password_generator(length: int = len):
alp = string.ascii_letters + string.digits +
string.punctuation
password =
"".join(random.choice(alp) for i in range(length))
return password
pass_gen = password_generator()
print("Password Generated:
"+pass_gen)
else:
print("The length must be equal or
greater than 8")
5. Results:
Test 1: The length of the password is shorter than the
appropriate size “8”
Test 2: The length of the password is of the
appropriate size.
Comments
Post a Comment