Created
November 11, 2022 13:22
-
-
Save samg11/7d5620e18b1bcca0eaaf00c202b489e4 to your computer and use it in GitHub Desktop.
Quickly generates a secure password in your terminal
This file contains 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
import sys | |
import random | |
def generate_password(length, no_symbols=False): | |
chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
if not no_symbols: | |
chars += '~!@#$%^&*()_-+={[}]|:;<,>.?/' | |
pw = '' | |
for _ in range(length): | |
pw += random.choice(chars) | |
return pw | |
if __name__ == '__main__': | |
try: | |
pw_length = int(input('How many characters would you like your password to be? ').strip()) | |
except ValueError: | |
pw_length = 50 | |
print(f'Password will be {pw_length} characters long') | |
no_symbols_check = False | |
if len(sys.argv) > 1: | |
no_symbols_check = sys.argv[1] == 'no-symbols' | |
print(generate_password(pw_length, no_symbols_check)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment