Skip to content

Instantly share code, notes, and snippets.

@samg11
Created November 11, 2022 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samg11/7d5620e18b1bcca0eaaf00c202b489e4 to your computer and use it in GitHub Desktop.
Save samg11/7d5620e18b1bcca0eaaf00c202b489e4 to your computer and use it in GitHub Desktop.
Quickly generates a secure password in your terminal
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