In this post we will learn about How to generate a password using python programming language. In this program we using "Random" package.
we need to create a program that takes the length of the password and generates a random password of the same length. In this article, I’ll walk you through how to write a Python program to generate a password.
Python Program language to Generate Password
To write a Python program to create a password, declare a string of numbers + uppercase + lowercase + special characters. Take a random sample of the string of a length given by the user:
Source Code:
import random
passlen = int(input("enter the length of password:"))
a1="abcdefghijklmnopqrstuvwxy"
A1="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
num="z01234567890"
avalue="!@#$%^&*()?"
final=a1+A1+num+avalue
p = "".join(random.sample(final,passlen ))
print(p)(code-box)
Output: