Skip to main content
edited tags
Link
Reinderien
  • 71.1k
  • 5
  • 76
  • 256
Tweeted twitter.com/StackCodeReview/status/1617401743725285379
fix link so excess protocol is not appended at end, and make text hyperlink
Source Link

I have the following code here: https://github.com/jakelarson06/python-password-generatorhttps://code here

I want feedback of the general readability, style, and security (as it's a password generator), and if you would do anything differently.

I have the following code here: https://github.com/jakelarson06/python-password-generatorhttps://

I want feedback of the general readability, style, and security (as it's a password generator), and if you would do anything differently

I have the following code here

I want feedback of the general readability, style, and security (as it's a password generator), and if you would do anything differently.

Source Link

Python Password Generator with custom parameters

I have the following code here: https://github.com/jakelarson06/python-password-generatorhttps://

It's a password generator that lets you choose a completely random password with a certain length of a custom password with different amounts of character types.

I want feedback of the general readability, style, and security (as it's a password generator), and if you would do anything differently

The code:

# Imports libraries
import secrets
import string

# Creates list of every possible character for the "general" option
fulllist = string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuation
# Asks user what option they want
generalorcustom = input("General (g) or custom (c) password: ")
# Randomly grabs a character from the 'fulllist' as many times as specified
def general():
    return ''.join(secrets.choice(fulllist) for i in range(int(length))) 

def custom():
    # Inputs how many of each character user wants
    lowernum = input("Lowwer case character count: ")
    uppernum = input("Upper case character count: ")
    digitnum = input("Digit count: ")
    specnum = input("Special character count: ")
    # Creates list, then randomly adds each characters of each type to list for specified amount
    temp_list = []
    temp_list.extend(list(secrets.choice(string.ascii_lowercase) for i in range(int(lowernum))))
    temp_list.extend(list(secrets.choice(string.ascii_uppercase) for i in range(int(uppernum))))
    temp_list.extend(list(secrets.choice(string.digits) for i in range(int(digitnum))))
    temp_list.extend(list(secrets.choice(string.punctuation) for i in range(int(specnum))))
    # Creates final string, and randomly adds contents of temp_list to final string
    password = ''
    rangevar = list(range(len(temp_list)))
    while len(rangevar) > 0:
        picked_item = secrets.choice(rangevar)
        password += temp_list[picked_item]
        rangevar.remove(picked_item)

    return password
# Checks and executes function as user requested
if generalorcustom.lower() == "general" or generalorcustom.lower() == "g":
    length = input("Password length: ")
    print(general())
elif generalorcustom.lower() == "custom" or generalorcustom.lower() == "c":
    print(custom())
else:
    print('Error, invalid input')