def on_confirm_press(self, event): """ Method override for the callback when the button is pressed It checkes wether the given login and password by the user is correct and either calls 'return_succesful_login' or 'display_error_message' """ username = self._user_box.text() password = self._password_box.text() if len(username) > 0 and len(password) > 0: userpassregex = '([a-z]|[0-9]|\.)*' resu = re.match(userpassregex, username) resp = re.match(userpassregex, password) if resu.span()[1] == len(resu.string) and resp.span()[1] == len( resp.string): credHandler = CredentialsHandler(username, password) credHandler.encrypt_credentials() if credHandler.are_cred_valid(): self.return_succesful_login() else: self._error_message.setText( "Failed to login, bad credentials") self.display_error_message() else: self._error_message.setText( "Invalid characters, use only a-z, 0-9 and periods (.)") self.display_error_message()
def test_hashes_nonempty_bytes(self): db = DatabaseHandler(db_path="pytests/", dbIsTemp=True) credh = CredentialsHandler('testusername', b'nonemptytestpassword') credh.encrypt_credentials() self.assertEqual(credh.password, '3217aa106d566c22fb0f2e44af0e28d024d4fa98') DatabaseHandler.destroy_database()
def test_hashes_empty_bytes(self): db = DatabaseHandler(db_path="pytests/", dbIsTemp=True) credh = CredentialsHandler('testusername', b'') credh.encrypt_credentials() self.assertEqual(credh.password, 'da39a3ee5e6b4b0d3255bfef95601890afd80709') DatabaseHandler.destroy_database()
def test_credentials_validation(self): db = DatabaseHandler(db_path="pytests/", dbIsTemp=True) credh = CredentialsHandler('testusername', b'nonemptytestpassword') credh.encrypt_credentials() # Until we have no database connected here this will always pass, if it fails # rewrite the test in a way it's taking into consideration the database self.assertEqual(credh.are_cred_valid(), False) DatabaseHandler.destroy_database()
def test_basic_operations(self): db = DatabaseHandler(db_path="pytests/", dbIsTemp=True) credh = CredentialsHandler('basic_username', 'basic_password') credh.encrypt_credentials() self.assertEqual(credh.does_user_exist(), False) self.assertEqual(credh.are_cred_valid(), False) credh.create_user() self.assertEqual(credh.does_user_exist(), True) self.assertEqual(credh.are_cred_valid(), True) DatabaseHandler.destroy_database()
def on_confirm_press(self, event): """ Method override for the callback when the button is pressed It checkes wether the given login is possible and doesn't exist if so it creates the user and calls 'return_succesful_login' or if not 'display_error_message' """ username = self._user_box.text() password = self._password_box.text() if len(username) > 0 and len(password) > 0: userpassregex = '([a-z]|[0-9]|\.)*' resu = re.match(userpassregex, username) resp = re.match(userpassregex, password) if resu.span()[1] == len(resu.string) and resp.span()[1] == len( resp.string): credHandler = CredentialsHandler(username, password) credHandler.encrypt_credentials() if not credHandler.does_user_exist(): credHandler.create_user() self.return_succesful_login() else: self.display_error_message() self._error_message.setText( "Login exists, pick different one") else: self._error_message.setText( "Invalid characters, use only a-z, 0-9 and periods (.)") self.display_error_message()