|
|
Save admin credentials to file
This function saves the linkedlist data from adminHead to the file resources/db/admin_credentials.dat . .dat is used to store credentials in binary format for surface level security.
- Note
- The file path 'resources/db' is relative to the project root directory. Make sure that the folder exists also to run the program from the root directory.
- Postcondition
- The linkedlist data is saved to the file.
- Exceptions
-
fopen() | - If the file cannot be opened, an error message is displayed. |
fwrite() | - If the file cannot be written, an error message is displayed. |
|
void | saveAdminCredentials (void) |
|
|
Load admin credentials from file
This function loads the admin credentials from the file resources/db/admin_credentials.dat and stores it in the adminHead linkedlist. If file is not found, it creates a new admin with default credentials and stores it in the file.
- Note
- The file path 'resources/db' is relative to the project root directory. Make sure that the folder exists also to run the program from the root directory.
- Postcondition
- If the file is not found, a new admin is created with default credentials and stored in the file. If the file is found, the admin credentials are loaded from the file and stored in the
adminHead linkedlist.
- Exceptions
-
fopen() | - If the file cannot be opened, an error message is displayed. |
malloc() | - If memory allocation fails, an error message is displayed. |
|
void | loadAdminCredentials (void) |
|
|
Check if admin exists
This function traverses the adminHead linkedlist and checks if the username exists in the list.
- Parameters
-
[in] | username | Admin username |
- Returns
- True if admin exists, False otherwise
- Precondition
username is not empty and valid
- Postcondition
- If the
username is found in the linkedlist, the function returns true, otherwise false.
- Exceptions
-
If | the username is empty, an error message is displayed. |
If | the username is invalid, an error message is displayed. |
|
bool | adminExists (const char *username) |
|
|
Validate admin credentials
This function traverses the adminHead linkedlist and checks if the pair of username and password match.
- Parameters
-
[in] | username | Admin username |
[in] | password | Admin password |
- Returns
- True if credentials are valid, False otherwise
- Precondition
username and password are not empty and valid
- Postcondition
- If the pair of
username and password are found in the linkedlist, the function returns true, otherwise false.
- Exceptions
-
If | the username or password is empty, an error message is displayed. |
If | the username is invalid, an error message is displayed. |
|
bool | validateAdmin (const char *username, const char *password) |
|
|
Add admin
This function adds a new admin to the adminHead linkedlist and saves the updated linkedlist to the file resources/db/admin_credentials.dat .
- Parameters
-
[in] | username | Admin username |
[in] | password | Admin password |
[in] | currentAdminUsername | Current admin username |
[in] | currentAdminPassword | Current admin password |
- Returns
- True if admin is added, False otherwise
- Note
- The file path 'resources/db' is relative to the project root directory. Make sure that the folder exists also to run the program from the root directory.
- Precondition
username and password are not empty
-
currentAdminUsername and currentAdminPassword are not empty
-
username and currentAdminUsername are valid
- Postcondition
- If the
username and password are not found in the linkedlist, the function adds the new admin to the linkedlist and saves the updated linkedlist to the file.
- Exceptions
-
If | the username or password is empty, an error message is displayed. |
If | the username or currentAdminUsername is invalid, an error message is displayed. |
If | the pair of currentAdminUsername and currentAdminPassword is invalid, means that the current admin credentials are not valid, an error message is displayed. |
If | the username already exists, an error message is displayed. |
malloc() | - If memory allocation fails, an error message is displayed. |
|
bool | addAdmin (const char *username, const char *password, const char *currentAdminUsername, const char *currentAdminPassword) |
|
|
Delete admin
This function deletes an admin from the adminHead linkedlist and saves the updated linkedlist.
- Parameters
-
[in] | username | Admin username |
[in] | currentAdminUsername | Current admin username |
[in] | currentAdminPassword | Current admin password |
- Returns
- True if admin is deleted, False otherwise
- Precondition
username is not empty
-
currentAdminUsername and currentAdminPassword are not empty
-
username and currentAdminUsername are valid
- Postcondition
- If the
username is found in the linkedlist, the function deletes the admin from the linkedlist and saves the updated linkedlist to the file.
- Exceptions
-
If | the pair of currentAdminUsername and currentAdminPassword is invalid, means that the current admin credentials are not valid, an error message is displayed. |
If | the username does not exist, an error message is displayed. |
If | the username is the same as the current admin username, an error message is displayed. |
If | the username or currentAdminUsername is invalid, an error message is displayed. |
|
bool | deleteAdmin (const char *username, const char *currentAdminUsername, const char *currentAdminPassword) |
|
|
Change admin password
This function changes the password of an admin in the adminHead linkedlist and saves the updated linkedlist.
- Parameters
-
[in] | username | Admin username |
[in] | oldPassword | Old password |
[in] | newPassword | New password |
- Returns
- True if password is changed, False otherwise
- Precondition
username and oldPassword are not empty
-
username is valid
-
newPassword is not empty
- Postcondition
- If the pair of
username and oldPassword are found in the linkedlist, the function changes the password of the admin and saves the updated linkedlist.
- Exceptions
-
If | the username or oldPassword is empty, an error message is displayed. |
If | the pair of username and oldPassword is not found in the linkedlist, an error message is displayed. |
If | the username is invalid, an error message is displayed. |
|
bool | changeAdminPassword (const char *username, const char *oldPassword, const char *newPassword) |
|
|
Display all admins
This function displays all admins in the adminHead linkedlist.
- Postcondition
- If the
adminHead linkedlist is not empty, the function displays all admins in the linkedlist.
|
void | displayAdmin (void) |
|
|
Free admin list
This function frees the memory allocated for the adminHead linkedlist.
- Postcondition
- The memory allocated for the
adminHead linkedlist is freed.
|
void | freeAdmin (void) |
|
Admin manager source file.
This file contains the implementation of the admin manager module.
- Author
- CrimsonCare Team
- Date
- 2025-01-18
- Copyright
- Copyright (c) 2025 CrimsonCare Team
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Definition in file admin_manager.c.