In this article, we are Going to show you how to Create a Random Password Generator using python. For doing this Project We are going to use two python Module Named Random and String.
Now Let's Begin to install Python Modules using the Follwoing command
1) pip install random2
2) pip install strings
By doing this command it will install Random and Strings module. Now let's import this module on our project by doing the follwoing command
1) import random
2) import string
Now Let's allow user to Enter the length of the password by using the following command.
3) passlen = int(input("Enter the length of password: "))
This command will allow user to input the length of the password to be generated. Now Let's Write the main code of this programm
4) lower = string.ascii_lowercase
5) upper = string.ascii_uppercase
6) num = string.digits
7) symbols = string.punctuation
Lowercase and uppercase letters, as well as numbers and symbols, have been saved. Now let's store all the data one a variable named total
8) total = lower + upper + num + symbols
Finally, we'll utilise the random module to generate the password. We can do that by the following command
9) res = random.sample(total,passlen)
10) password = "".join(res)
Now Let's Print the password.
11) print(password)
You can see the code and output below.
import random
import string
passlen = int(input("Enter the length of password: "))
lower = string.ascii_lowercase
upper = string.ascii_uppercase
num = string.digits
symbols = string.punctuation
total = lower + upper + num + symbols
res = random.sample(total,passlen)
password = "".join(res)
print(password)
You can see the output of the code from below or you can download the code from Below Button