Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 59cad72

Browse files
Completing 1.2.3
1 parent 623b82e commit 59cad72

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

API/API.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"api": "RLR",
2+
"api": "",
33
"username": "",
44
"password": "",
55
"exclusion_titles": [","]

DataBase.py

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,49 @@ def check_ERROR(value):
3232
return False
3333

3434

35+
def check_admin_password(password):
36+
"""
37+
Check if the provided password matches the password of the 'admin' user in the SQLite database.
38+
39+
Args:
40+
password (str): The password to be checked.
41+
42+
Returns:
43+
bool: True if the password matches, False otherwise.
44+
45+
Raises:
46+
Exception: If an error occurs while executing the SQL query or fetching the result.
47+
48+
"""
49+
# Connect to the SQLite database (or create it if it doesn't exist)
50+
conn = sqlite3.connect('users.db')
51+
52+
# Create a cursor object using the cursor() method
53+
cursor = conn.cursor()
54+
55+
# SQL query to select the admin user's username and password
56+
query = "SELECT username, password FROM Users WHERE username='admin'"
57+
58+
try:
59+
# Execute the query
60+
cursor.execute(query)
61+
62+
# Fetch the result
63+
result = cursor.fetchone()
64+
65+
# Check if the fetched row exists and the password matches
66+
if result and result[1] == password: # Compare the second column (index 1) with the provided password
67+
return True
68+
else:
69+
return False
70+
except Exception as e:
71+
print(f"An error occurred: {e}")
72+
return False
73+
finally:
74+
# Close the connection
75+
conn.close()
76+
77+
3578
class UserManager:
3679
# Class to handle user management
3780
def __init__(self, db_name="users.db"):
@@ -131,7 +174,8 @@ def verify_password(self, username, password):
131174
if password == stored_password:
132175
return True
133176
return False
134-
except Exception:
177+
except Exception as e:
178+
log.info(f"An error occurred while verifying the password. as {e}")
135179
return False
136180

137181
def create_db(self, username, exclusion_titles, password=None):
@@ -915,15 +959,15 @@ def init():
915959
log.info(
916960
f"A request has been made to remove the user {username} from the database"
917961
)
918-
if username is not "admin":
962+
if username != "admin":
919963
DATA = um.remove(username, password)
920964
if not check_ERROR(DATA):
921965
log.info("User removed successfully based on the request")
922966
else:
923967
DATA = "ERROR Admin cannot be removed && 401"
924968

925969
elif api == "RLR":
926-
if um.verify_password(username, password) and username == "admin":
970+
if check_admin_password(password):
927971
DATA = "LOG"
928972
else:
929973
DATA = "ERROR Invalid Username or Password && 401"
@@ -948,6 +992,8 @@ def init():
948992
try:
949993
with open("Admin.secrets", "r") as admin:
950994
password = admin.read()
951-
except Exception:
995+
except Exception as e:
996+
log.info("Admin password not found" + str(e))
952997
password = None
953998
um.create_db("admin", "", password)
999+
os.remove("passwords.txt")

0 commit comments

Comments
 (0)