Created
October 3, 2022 18:14
-
-
Save Zillionx/ea226249fa86dbc25279578597c5703c to your computer and use it in GitHub Desktop.
Password generator (Python3)
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
#!/usr/bin/env python3 | |
import string | |
import random | |
## characters to generate password from | |
characters = list(string.ascii_letters + string.digits + "!@#$%^&*()") | |
def generate_random_password(): | |
## length of password from the user | |
length = int(input("Enter password length: ")) | |
## shuffling the characters | |
random.shuffle(characters) | |
## picking random characters from the list | |
password = [] | |
for i in range(length): | |
password.append(random.choice(characters)) | |
## shuffling the resultant password | |
random.shuffle(password) | |
## converting the list to string | |
## printing the list | |
print("".join(password)) | |
## invoking the function | |
generate_random_password() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment