Created
May 13, 2021 14:56
-
-
Save thecraftman/dc06b4d143a66fa7ab8461e61c58bc1a to your computer and use it in GitHub Desktop.
Randomly create passwords in Python using the Input variable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Before running this code, make sure you have Python 3 and above Installed on your machine. | |
# Run the file using python3 pythongenerator.py | |
# Creating a password generator in Python | |
# string library to generate the password | |
import string | |
# generate secure and random passwords | |
import random | |
# create a function for the password generator | |
def gen(): | |
# create a variable `s1` to give the uppercase letters | |
s1 = string.ascii_uppercase | |
# create a variable `s2` to give the uppercase letters | |
s2 = string.ascii_lowercase | |
# create a variable `s3` to give the digits | |
s3 = string.digits | |
# create a variable `s4` to give the special characters | |
s4 = string.punctuation | |
# we want the password generator to take the input from the user, Create an input variable for it | |
passlen = int(input("Enter the password length\n")) | |
# create a list, to add all the variables into a list called `s` | |
s = [] | |
s.extend(list(s1)) | |
s.extend(list(s2)) | |
s.extend(list(s3)) | |
s.extend(list(s4)) | |
# randomly shuffle the variables | |
random.shuffle(s) | |
# pass the list s from 0 till the length of the password gotten from the user | |
pas = ("".join(s[0:passlen])) | |
print(pas) | |
# when you run the file you can see that all the variables and special symbols are saved as a list | |
gen() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment