diff --git a/banking_app/login.py b/banking_app/login.py index 2bbab36..63852b1 100644 --- a/banking_app/login.py +++ b/banking_app/login.py @@ -1,4 +1,5 @@ # login.py - Placeholder for login functionality +import csv def login(username, password): """ @@ -33,3 +34,38 @@ 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("The fields are empty") + + symbols = ['!', '@', '#', '$', '%', '&', '*', '?', '~'] + + for n in symbols: + if n in username: + raise ValueError + if username == '': + raise ValueError + elif password == "": + raise ValueError + else: + return username, password + +def checking_info(username, password): + with open ("database.csv", mode='r') as f: + contents = csv.DictReader(f) + for line in contents : + if line["username"] == username: + if line["password"] == password: + return True + else: + return False + + return False + + + + + + + + + diff --git a/banking_app/signup.py b/banking_app/signup.py index a920e5b..f783b06 100644 --- a/banking_app/signup.py +++ b/banking_app/signup.py @@ -1,4 +1,5 @@ # signup.py - Placeholder for signup functionality +import re def signup(username, password, email): """ @@ -35,3 +36,31 @@ 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("The fields must not be empty") + + + email__ = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$' + if not re.match(email__, email): + raise ValueError("Invalid email format") + + if len(password) < 8: + raise ValueError("Password must be at least 8 characters long") + + if not any(character.islower() for character in password): + raise ValueError("Password must contain at least one lowercase letter") + + if not any(character.isupper() for character in password): + raise ValueError("Password must contain at least one uppercase letter") + + if not any(character.isdigit() for character in password): + raise ValueError("Password must contain at least one digit") + + + return True + + + + + \ No newline at end of file diff --git a/functions_to_test.py b/functions_to_test.py index 330fa02..2d7c034 100644 --- a/functions_to_test.py +++ b/functions_to_test.py @@ -4,31 +4,58 @@ def add_numbers(a, b): pass def find_maximum(a, b, c): - pass + return max(a, b, c) def is_palindrome(string): - pass + return string == string[::-1] def count_word_occurrences(text, word): - pass + text = text.lower() + word = word.lower() + words = text.split() + count = words.count(word) + + return count def read_file_lines(filepath): - pass + with open(filepath, 'r') as f: + contents = f.readlines + return contents def factorial(n): - pass + x = 1 + for i in range(1,n+1): + x*= i + return x def is_prime(n): - pass + if not isinstance(n, int): + raise TypeError(f"{n} is not an integer. Input must be an integer.") + + if n <= 1: + raise ValueError(f"{n} is not a prime number") + for i in range(2, int(n**0.5) + 1): + if n % i == 0: + raise ValueError(f"{n} is not a prime number") + return True + def sort_numbers(numbers): pass def factorial(n): - pass + x = 1 + for i in range(1,n+1): + x*= i + return x + def fibonacci(n): - pass + if n == 0: + return 0 + if n == 1: + return 1 + return fibonacci(n-1) + fibonacci(n-2) def tower_of_hanoi(n, source, auxiliary, target): @@ -48,7 +75,12 @@ def tower_of_hanoi(n, source, auxiliary, target): >>> tower_of_hanoi(3, 'A', 'B', 'C') [('A', 'C'), ('A', 'B'), ('C', 'B'), ('A', 'C'), ('B', 'A'), ('B', 'C'), ('A', 'C')] """ - pass + if n == 1: + + print(f"Move disk 1 from {source} to {target}") + return + + class Person: def __init__(self, name, age):