Rapportsystem API - of D03N
Hovedprosjekt FiV Programmering 20-24
Loading...
Searching...
No Matches
login_validation.py
Go to the documentation of this file.
1import os
2import sys
3
4current_directory = os.getcwd()
5sys.path.append(os.path.join(current_directory)) #path dir containing pw_manager.py
6from PW_hashHandler import pw_manager as PW
7from SQLAdminConnections import SQL_AdminQuerys as SQLQ
8from SQLAdminConnections import SQL_AdminConnector as SQLC
9
10
11#class for validating login credentials
13
14 def __init__(self, username, clean_pw):
15 self.username = username
16 self.clean_pw = clean_pw
17
18 #defines validation function
20 #makes object of SQLConAdmin class
21 adminConnection = SQLC.SQLConAdmin()
22 #sets up connector with admin credentials
23 connection = adminConnection
24
25 connection.connect()
26 connection.execute_query(SQLQ.SQLQueries.use_users_database(), None)
27 connection.execute_query(SQLQ.SQLQueries.get_hashed_password_and_id_by_username(self.username))
28
29 #print(SQLQ.SQLQueries.get_hashed_password_and_id_by_username(self.username))
30 result = connection.execute_query(SQLQ.SQLQueries.get_hashed_password_and_id_by_username(self.username))
31 connection.close()
32
33 # Initialize default values for the response list: [is_valid, user_id]
34 response_list = [False, None, None]
35 print(result)
36
37 # If there's no result, the username is not in the database.
38 if not result:
39 return response_list
40
41 # Extract user ID and hashed password from result
42 user_id, hashed_pw,accountType = result[0]
43
44 # Validate password
45 if PW.check(self.clean_pw, hashed_pw):
46 response_list[0] = True # Set is_valid to True
47 response_list[1] = user_id # Set user_id
48 response_list[2] = accountType
49
50 print(response_list)
51 return response_list
52
53
54
55
56
57
58
__init__(self, username, clean_pw)