diff --git a/banking_app/login.py b/banking_app/login.py index 2bbab36..9d0ce1f 100644 --- a/banking_app/login.py +++ b/banking_app/login.py @@ -1,5 +1,5 @@ # login.py - Placeholder for login functionality - +import csv def login(username, password): """ Handles the user login process by verifying the provided username and password. @@ -33,3 +33,24 @@ def login(username, password): - bool: `True` if login is successful, `False` if login fails, or raises a `ValueError` for invalid input. """ + + if not username or not password: + raise ValueError + + for char in username: + if not char.isalnum(): + raise ValueError() + + + path = r"C:\Users\User\Byte-me-python\database.csv" + with open(path, mode='r', newline='', encoding='utf-8') as file: + reader = csv.reader(file) + for row in reader: + + if username in row and row[username] == password: + return True + else: + return False + + return True + diff --git a/banking_app/signup.py b/banking_app/signup.py index a920e5b..acf73e4 100644 --- a/banking_app/signup.py +++ b/banking_app/signup.py @@ -1,5 +1,5 @@ # signup.py - Placeholder for signup functionality - +import re def signup(username, password, email): """ Handles the user signup process by validating the provided username, password, and email. @@ -35,3 +35,19 @@ def signup(username, password, email): Returns: - bool: `True` if the signup is successful, otherwise raises a `ValueError` for invalid input. """ + + if not username or not password or not email: + raise ValueError() + + email_regex = r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$' + if not re.match(email_regex, email): + raise ValueError() + + + if len(password) < 8 or not any(c.isupper() for c in password) or not any(c.islower() for c in password) or not any(c.isdigit() for c in password): + raise ValueError() + + if password.isdigit() or password.lower() in ["password", "123456", "qwerty"]: + raise ValueError() + + return True \ No newline at end of file diff --git a/functions_to_test.py b/functions_to_test.py index 330fa02..0096c74 100644 --- a/functions_to_test.py +++ b/functions_to_test.py @@ -1,34 +1,97 @@ # Placeholder functions for Python basics, to be implemented later def add_numbers(a, b): - pass + if not isinstance(a, (int,float)) or not isinstance(b, (int,float)): + raise TypeError + + return a + b + def find_maximum(a, b, c): - pass + return max(a,b,c) def is_palindrome(string): - pass + if not type(string) == str: + raise TypeError + + return string == string[::-1] def count_word_occurrences(text, word): - pass + if type(text) == int: + raise TypeError + return text.lower().count(word) def read_file_lines(filepath): - pass + with open(filepath, 'r', errors="ignore") as file: + return file.readlines() def factorial(n): - pass + if not isinstance(n, int): + raise TypeError() + + if n < 0: + raise ValueError() + + if n == 0 or n == 1: + return 1 + + return n * factorial(n - 1) + def is_prime(n): - pass + if not isinstance(n, int): + raise TypeError() + + if n < 0: + raise ValueError() + + if n < 2: + return False + + for i in range(2, int(n**0.5) + 1): + if n % i == 0: + return False + + return True def sort_numbers(numbers): - pass + for i in numbers: + if not isinstance(i, int): + raise TypeError() + + return sorted(numbers) def factorial(n): - pass + if not isinstance(n, int): + raise TypeError() + + if n < 0: + raise ValueError() + + if n == 0 or n == 1: + return 1 + + return n * factorial(n - 1) + def fibonacci(n): - pass + if not isinstance(n, int): + raise TypeError() + + if n < 0: + raise ValueError() + + if n == 0: + return 0 + if n == 1: + return 1 + + a, b = 0, 1 + for _ in range(2, n + 1): + a, b = b, a + b + + return b + def tower_of_hanoi(n, source, auxiliary, target): @@ -52,7 +115,13 @@ def tower_of_hanoi(n, source, auxiliary, target): class Person: def __init__(self, name, age): - pass + if not isinstance(name, str): + raise TypeError("Name must be a string.") + if not isinstance(age, int): + raise TypeError("Age must be an integer.") + + self.name = name + self.age = age if __name__ == "__main__": diff --git a/tests/test_functions.py b/tests/test_functions.py index ae682d2..cfa9a0e 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -43,10 +43,9 @@ def test_factorial_0_and_1(self): 1) - def test_factorial_negative(self): - self.assertEqual(factorial(-1), - "") - +def test_factorial_negative(self): + with self.assertRaises(ValueError): + factorial(-1) def test_factorial_5(self): self.assertEqual(factorial(5),