def menu(): choice = input("----------------------------------------\nWelcome To 2Password\n1 - Check Password\n2 - Generate Password\n3 - Quit\n>>> ") while choice != '1' and choice != '2' and choice != '3': # data validation choice = input("ERROR\n>>> ") print("--------------------") # checking user choice and directing them to desired function if choice == '1': pCheck.password_check() end_of_task() elif choice == '2': pGen.final_pass_gen() end_of_task() elif choice == '3': print("\n\n--------------------\nThank you for using 2Password\n--------------------") quit() # quitting
def test_nonums(self): rules = pc._rules_dictionary(length=10, must_have_numbers=False, must_have_caps=True) for pw in nonums_passw: with self.subTest(i=pw): self.assertTrue(pc.password_check(pw, rules))
def name_password_change(data_base,choice,name): count=1 while True: print("Confirm your password") password=hash(input()) #encode_check=hashlib.sha256(b'password') if data_base[name][1]==password: #os.system('clear') if choice in ['1','username','USERNAME','Username']: new_name=name_check(data_base,1) db=pymysql.connect('localhost','nayan','1234','user_database') cursor=db.cursor() cursor.execute("UPDATE data SET username=%s WHERE data_id=%s",(new_name,data_base[name][0])) db.commit() db.close() temp=data_base[name] del data_base[name] data_base[new_name]=temp print("\nUsername changed successfully:") time.sleep(2) return(new_name) break else: new_password=password_check(c=2) encoded=hash(new_password) db=pymysql.connect('localhost','nayan','1234','user_database') cursor=db.cursor() cursor.execute("UPDATE data SET password=%s WHERE username=%s",(encoded,name)) db.commit() db.close() data_base[name][1]=encoded print("\nPassword changed successfully:") time.sleep(2) return(name) break else: if count==3: os.system('clear') print("Max password attempts reached") break else: #os.system('clear') print("Incorrect password") count=count+1
def test_upper(self): self.assertFalse(password_check('pa$5word'), msg='pa$5word does not meet requirements')
def test_superlong(self): rules = pc._rules_dictionary(length=20) self.assertTrue(pc.password_check('Aabcdvwxyz101abcdewxyzZ', rules))
def test_strong(self): rules = pc._rules_dictionary(length=20) for pw in strong_passw: with self.subTest(i=pw): self.assertFalse(pc.password_check(pw, rules))
def test_supershort(self): rules = pc._rules_dictionary(length=4) self.assertFalse(pc.password_check('ab1', rules))
def test_short(self): rules = pc._rules_dictionary(length=4) for pw in short_passw: with self.subTest(i=pw): self.assertTrue(pc.password_check(pw, rules))
def test_len_20(self): self.assertTrue(password_check('This!$MyPassword1234'), msg='This!$MyPassword1234 meets the requirements')
def test_nonums(self): rules = pc._rules_dictionary() for pw in nonums_passw: with self.subTest(i=pw): self.assertFalse(pc.password_check(pw, rules))
def test_password_length_short(): password = "******" expected = password_check(password) actual = False assert actual==expected, f"Password length incorrect, actual={actual}, expected={expected}"
def test_password_contains_special_symbol(): password = "******" expected = password_check(password) actual = False message = f"Password did not contain special symbol but passed, actual={actual}, expected={expected}" assert actual == expected, message
def test_digit(self): self.assertFalse(password_check('Pas$word'), msg='Pas$word does not meet requirements')
def test_password_not_contains_one_upper(): password = "******" expected = password_check(password) actual = False message = f"""Password format incorrect, does not contain upper, actual={actual}, expected={expected}""" assert expected == actual, message
def test_long(self): self.assertFalse( password_check('He11@dsfdjasklasasfdsa'), msg='He11@dsfdjasklasasfdsa does not meet requirements')
def test_short(self): self.assertFalse(password_check('He11@'), msg='He11@ does not meet requirements')
def test_password_contains_one_upper(): password = "******" expected = password_check(password) actual = False message = f"Password did not contain one uppercase but passed, actual={actual}, expected={expected}" assert actual == expected, message
def wrapped_password_check(): password = request.get_json()['password'] result = password_check(password, _rules_dictionary()) return jsonify(result)
def test_short(self): self.assertFalse(password_check('hello'), msg='hello does not meet requirements')
def test_password_length_correct(): password = "******" expected = password_check(password) actual = True assert actual == expected, f"Password is marked as incorrect, but is correct, actual={actual}, expected={expected}"
def test_lower(self): self.assertFalse(password_check('PA$5WORD'), msg='PA$5WORD does not meet requirements')
def test_len_8(self): self.assertTrue(password_check('Pa$5word'), msg='Pa$%word meets the requirements')
def test_password_contains_one_digit(): password = "******" expected = password_check(password) actual = False message = f"Password ({password}) did not contain digit but passed, actual={actual}, expected={expected}" assert actual == expected, message