Skip to main content
added 79 characters in body
Source Link
Ben A
  • 10.8k
  • 5
  • 38
  • 103

Reliability

I get that this program is meant for you to continue learning python, but please don't use any passwords generated by this program. Especially since your strength check is really weak. I.E, this function that checks the strength thinks Password123 is a strong password. Don't use it :-).

Checking password strength

This function can be reduced to the following:

import re

def check_password_strength(password: str) -> bool:

    tests = [
        re.compile(r'\w{8,}'),
        re.compile(r'\d+'),
        re.compile(r'[a-z]'),
        re.compile(r'[A-Z]')
    ]

    return not any(test.search(password) == None for test in tests)

Instead of creating individual variables for each regex, make a list and loop through it checking the password against each value in the list.

Take a look at zxcvbn, which is a password strength tester written by Dropbox. It's in javascript, but if you understand the main algorithm you'll be able to write it in python.

Type Hints

These allow you to display what types of parameters are accepted and what types are returned by your functions. Take a look at the function above for an example. Accepts password as a str, and returns a bool(ean) value.

Creating strings

This

password = ''
for c in range(length):
    password += random.choice(chars)
print(password)

can be written like this (thanks Graipher)

password = ''.join(random.choicechoices(chars) for _ in, range(lengthk=length))

The _ just means the variable in the loop isn't used, and should be ignored.

Reliability

I get that this program is meant for you to continue learning python, but please don't use any passwords generated by this program. Especially since your strength check is really weak. I.E, this function that checks the strength thinks Password123 is a strong password. Don't use it :-).

Checking password strength

This function can be reduced to the following:

import re

def check_password_strength(password: str) -> bool:

    tests = [
        re.compile(r'\w{8,}'),
        re.compile(r'\d+'),
        re.compile(r'[a-z]'),
        re.compile(r'[A-Z]')
    ]

    return not any(test.search(password) == None for test in tests)

Instead of creating individual variables for each regex, make a list and loop through it checking the password against each value in the list.

Take a look at zxcvbn, which is a password strength tester written by Dropbox. It's in javascript, but if you understand the main algorithm you'll be able to write it in python.

Type Hints

These allow you to display what types of parameters are accepted and what types are returned by your functions. Take a look at the function above for an example. Accepts password as a str, and returns a bool(ean) value.

Creating strings

This

password = ''
for c in range(length):
    password += random.choice(chars)
print(password)

can be written like this

password = ''.join(random.choice(chars) for _ in range(length))

The _ just means the variable in the loop isn't used, and should be ignored.

Reliability

I get that this program is meant for you to continue learning python, but please don't use any passwords generated by this program. Especially since your strength check is really weak. I.E, this function that checks the strength thinks Password123 is a strong password. Don't use it :-).

Checking password strength

This function can be reduced to the following:

import re

def check_password_strength(password: str) -> bool:

    tests = [
        re.compile(r'\w{8,}'),
        re.compile(r'\d+'),
        re.compile(r'[a-z]'),
        re.compile(r'[A-Z]')
    ]

    return not any(test.search(password) == None for test in tests)

Instead of creating individual variables for each regex, make a list and loop through it checking the password against each value in the list.

Take a look at zxcvbn, which is a password strength tester written by Dropbox. It's in javascript, but if you understand the main algorithm you'll be able to write it in python.

Type Hints

These allow you to display what types of parameters are accepted and what types are returned by your functions. Take a look at the function above for an example. Accepts password as a str, and returns a bool(ean) value.

Creating strings

This

password = ''
for c in range(length):
    password += random.choice(chars)
print(password)

can be written like this (thanks Graipher)

password = ''.join(random.choices(chars, k=length))

The _ just means the variable in the loop isn't used, and should be ignored.

Source Link
Ben A
  • 10.8k
  • 5
  • 38
  • 103

Reliability

I get that this program is meant for you to continue learning python, but please don't use any passwords generated by this program. Especially since your strength check is really weak. I.E, this function that checks the strength thinks Password123 is a strong password. Don't use it :-).

Checking password strength

This function can be reduced to the following:

import re

def check_password_strength(password: str) -> bool:

    tests = [
        re.compile(r'\w{8,}'),
        re.compile(r'\d+'),
        re.compile(r'[a-z]'),
        re.compile(r'[A-Z]')
    ]

    return not any(test.search(password) == None for test in tests)

Instead of creating individual variables for each regex, make a list and loop through it checking the password against each value in the list.

Take a look at zxcvbn, which is a password strength tester written by Dropbox. It's in javascript, but if you understand the main algorithm you'll be able to write it in python.

Type Hints

These allow you to display what types of parameters are accepted and what types are returned by your functions. Take a look at the function above for an example. Accepts password as a str, and returns a bool(ean) value.

Creating strings

This

password = ''
for c in range(length):
    password += random.choice(chars)
print(password)

can be written like this

password = ''.join(random.choice(chars) for _ in range(length))

The _ just means the variable in the loop isn't used, and should be ignored.