def test_generate_with_everything(self): password = generate(25, include_uppercase=True, include_numbers=True, include_symbols=True) self.assertRegex( password, r'^(?=.*[a-z]*)(?=.*[A-Z])(?=.*\d)(?=.*[-_@.!])[A-Za-z\d\-_@.!]{25}$' )
if __name__ == "__main__": if not sys.argv[1:]: while True: try: text = input("""Select the option you like to run: 1) Generate a password 2) Validate a password 3) Check if password is pwned\n""") if text == "1": length = input('How many characters? ') uppercase = input('Should contain uppercase letters? ') numbers = input('Should contain numbers? ') symbols = input('Should contain special characters? ') print( generate(int(length), include_uppercase=uppercase, include_numbers=numbers, include_symbols=symbols)) break elif text == "2": length = input('Minimum length? ') lowercase = input('How many lowercase letters? ') uppercase = input('How many uppercase letters? ') numbers = input('How many numbers? ') symbols = input('How many symbols? ') password = input('Enter the password: ') validated = validate(password, lowercase=lowercase, uppercase=uppercase, numbers=numbers, symbols=symbols, length=length)
def test_generate_without_options(self): password = generate(8) self.assertRegex(password, r'^[a-z]{8}$')
def test_generate_with_0_length(self): password = generate(0) self.assertEqual(password, '')
def test_generate_with_length_lower_than_args(self): with self.assertRaises(RuntimeError): generate(2, include_uppercase=True, include_numbers=True, include_symbols=True)
def test_generate_with_symbols(self): password = generate(8, include_symbols=True) self.assertRegex(password, r'^(?=.*[a-z]*)(?=.*[_@.!\-])[a-z\-_@.!]{8}$')
def test_generate_with_numbers(self): password = generate(8, include_numbers=True) self.assertRegex(password, r'^(?=.*[a-z]*)(?=.*\d)[a-z\d]{8}$')
def test_generate_with_uppercase(self): password = generate(8, include_uppercase=True) self.assertRegex(password, r'^(?=.*[a-z]*)(?=.*[A-Z])[A-Za-z]{8}$')