Skip to content

Commit fee9302

Browse files
committed
Removed unused comments + headers
- Created potential fix to SQL Injection warning for delete animals, will monitor and modify/remove accordingly
1 parent 87e343e commit fee9302

7 files changed

+23
-17
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ dmypy.json
152152
# Cython debug symbols
153153
cython_debug/
154154

155+
# .vscode
156+
.vscode/
157+
155158
# PyCharm
156159
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157160
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore

N_P_P.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from notifications import notifications
55
from staff_portal import staff_portal
66
from view_animals import view_animals
7-
from common_functions import clear_screen, log_action, hash_password, get_mongodb_uri, load_animal_data
7+
from common_functions import clear_screen, log_action, hash_password, get_mongodb_uri
88
from login import login
99
from client_database import client_database
1010
from pymongo import MongoClient

add_animal.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def add_animal():
2929
print("Enter animal details or type 'exit' to cancel:")
3030

3131
# Input fields for animal data
32-
name = input(Fore.GREEN + "\nName: " + Style.RESET_ALL).strip().capitalize() # Capitalize the first letter
32+
name = input(Fore.GREEN + "\nName: " + Style.RESET_ALL).strip().capitalize()
3333

3434
# Check if user wants to exit
3535
if name.lower() == 'exit':
@@ -39,9 +39,9 @@ def add_animal():
3939
print_animal_table(animals)
4040
break
4141

42-
species = input(Fore.GREEN + "Species: " + Style.RESET_ALL).strip().capitalize() # Capitalize the first letter
43-
breed = input(Fore.GREEN + "Breed: " + Style.RESET_ALL).strip().capitalize() # Capitalize the first letter
44-
gender = input(Fore.GREEN + "Gender: " + Style.RESET_ALL).strip().capitalize() # Capitalize the first letter
42+
species = input(Fore.GREEN + "Species: " + Style.RESET_ALL).strip().capitalize()
43+
breed = input(Fore.GREEN + "Breed: " + Style.RESET_ALL).strip().capitalize()
44+
gender = input(Fore.GREEN + "Gender: " + Style.RESET_ALL).strip().capitalize()
4545
age = input(Fore.GREEN + "Age: " + Style.RESET_ALL).strip()
4646

4747
# Validate input fields

common_functions.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import re
23
from argon2 import PasswordHasher
34
from argon2.exceptions import VerifyMismatchError
45
import datetime
@@ -89,4 +90,9 @@ def get_input(prompt):
8990
return value
9091
else:
9192
print(Fore.RED + "\nThis field cannot be left blank. Please try again." + Style.RESET_ALL)
92-
time.sleep(2)
93+
time.sleep(2)
94+
95+
def sanitize_input(input_string):
96+
# Only allow alphanumeric characters and spaces
97+
pattern = re.compile('a-zA-z')
98+
return pattern.sub('', input_string)

edit_animal_entries.py

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
def get_animal_name():
2525
return input(Fore.CYAN + "Enter the name of the animal to modify (enter 'exit' to leave): " + Style.RESET_ALL).strip().capitalize()
26+
2627

2728
def get_field_choice():
2829
return input("Enter the number of the field to modify or 'exit' to cancel: ")
@@ -75,6 +76,8 @@ def modify_animal():
7576
if field_choice.lower() == 'exit':
7677
print(Fore.YELLOW + "\nExiting..." + Style.RESET_ALL)
7778
time.sleep(2)
79+
clear_screen()
80+
print_animal_table(animals)
7881
return
7982

8083
if field_choice.isdigit():

login.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import getpass
22
import time
33
from colorama import Fore, Style
4-
from common_functions import clear_screen, log_action, hash_password, verify_password, get_mongodb_uri, get_input
4+
from common_functions import clear_screen, log_action, hash_password, verify_password, get_mongodb_uri
55
from admin_dashboard import admin_dashboard
66
from pymongo import MongoClient
77

@@ -34,11 +34,8 @@ def change_admin_password(username):
3434
# Check if passwords match
3535
if new_password == confirm_password:
3636
# Generate salt and hash password
37-
3837
hashed_password = hash_password(new_password)
3938

40-
# Convert salt to hexadecimal string for serialization
41-
4239
# Update the password in the MongoDB collection for ADMIN
4340
users_collection.update_one(
4441
{'username': 'ADMIN'},
@@ -122,12 +119,6 @@ def login():
122119
time.sleep(2)
123120
exit()
124121

125-
def get_user_credentials():
126-
print("\n👤 User Login 👤")
127-
username = input("\nEnter your username: ")
128-
password = getpass.getpass("Enter your password: ")
129-
return username, password
130-
131122
def handle_successful_login(user, username, password):
132123
user_level = user['level']
133124
print("\nLogging in...")

view_animals.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import time
22
from colorama import Fore, Style
3-
from common_functions import clear_screen, load_animal_data, log_action, get_mongodb_uri
3+
from common_functions import clear_screen, load_animal_data, log_action, get_mongodb_uri, sanitize_input
44
from view_animal_profile import view_animals_full
55
from sudo_user_login import SudoUserLevel1, SudoUser
66
from edit_animal_entries import modify_animal
@@ -150,6 +150,9 @@ def sort_animals(animals, key='name', reverse=False):
150150
return sorted_animals
151151

152152
def delete_animal(animal_name):
153+
154+
animal_name = sanitize_input(animal_name)
155+
153156
try:
154157
animal_count = animals_collection.count_documents({"name": animal_name})
155158

0 commit comments

Comments
 (0)