Nishant Kumar
Cosmic Techie

Cosmic Techie

Create Strong Passwords using Password Generator Python

Nishant Kumar's photo
Nishant Kumar
·Jan 14, 2022·

1 min read

Create Strong Passwords using Password Generator Python

Photo by FLY:D on Unsplash

Subscribe to my newsletter and never miss my upcoming articles

We all use secret codes to secure our accounts and information and protect them from being hacked. Strong passwords are difficult to be hacked. We will go through a program to generate completely random and strong passwords, It’s a Random password Generator using Python.

Conventions for a strong password

  • Password should contain an UpperCase Character.
  • Password should contain a LowerCase Character.
  • Password should contain a Digit.
  • Password should contain a Special Character.
  • Password should contain at least 8 Characters.
import random
import string

Details=input("Please Enter the Details for Password,such as Site and Username : ")
Length=int(input("Please Enter the password length required: "))

# Get the Characters

lcase=string.ascii_lowercase # All LowerCase Characters
ucase=string.ascii_uppercase # All UpperCase Characters 
digi=string.digits           # All Digits
symbo=string.punctuation     # All Special Characters

# Combining All

# Extracting a Random Character from Each
random_lcase=random.choice(lcase)  # Eg: a
random_ucase=random.choice(ucase)  # Eg: Z
random_digi=random.choice(digi)    # Eg: 9
random_symbo=random.choice(symbo)  # Eg: &

# Combining the random charcaters: Eg: aZ9&
# Now, We have a combination of random characters of each type 

# Get a string with characters of intended length
for x in range(Length-4):

# Rndomize the string to get the completely random and a strong password

f = open("MyFile.txt", "a")# in append mode
f.write(Details+" : "+password+"\n")
print("Details saved to MyFile.txt")
Share this