CrimsonCare
CrimsonCare is a C project designed to provide a robust solution for blood management.
 
Loading...
Searching...
No Matches
admin_manager.c File Reference

Admin manager source file. More...

Go to the source code of this file.

Functions

saveAdminCredentials

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)
 
loadAdminCredentials

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)
 
adminExists

Check if admin exists

This function traverses the adminHead linkedlist and checks if the username exists in the list.

Parameters
[in]usernameAdmin 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
Ifthe username is empty, an error message is displayed.
Ifthe username is invalid, an error message is displayed.
bool adminExists (const char *username)
 
validateAdmin

Validate admin credentials

This function traverses the adminHead linkedlist and checks if the pair of username and password match.

Parameters
[in]usernameAdmin username
[in]passwordAdmin 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
Ifthe username or password is empty, an error message is displayed.
Ifthe username is invalid, an error message is displayed.
bool validateAdmin (const char *username, const char *password)
 
addAdmin

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]usernameAdmin username
[in]passwordAdmin password
[in]currentAdminUsernameCurrent admin username
[in]currentAdminPasswordCurrent 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
Ifthe username or password is empty, an error message is displayed.
Ifthe username or currentAdminUsername is invalid, an error message is displayed.
Ifthe pair of currentAdminUsername and currentAdminPassword is invalid, means that the current admin credentials are not valid, an error message is displayed.
Ifthe 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)
 
deleteAdmin

Delete admin

This function deletes an admin from the adminHead linkedlist and saves the updated linkedlist.

Parameters
[in]usernameAdmin username
[in]currentAdminUsernameCurrent admin username
[in]currentAdminPasswordCurrent 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
Ifthe pair of currentAdminUsername and currentAdminPassword is invalid, means that the current admin credentials are not valid, an error message is displayed.
Ifthe username does not exist, an error message is displayed.
Ifthe username is the same as the current admin username, an error message is displayed.
Ifthe username or currentAdminUsername is invalid, an error message is displayed.
bool deleteAdmin (const char *username, const char *currentAdminUsername, const char *currentAdminPassword)
 
changeAdminPassword

Change admin password

This function changes the password of an admin in the adminHead linkedlist and saves the updated linkedlist.

Parameters
[in]usernameAdmin username
[in]oldPasswordOld password
[in]newPasswordNew 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
Ifthe username or oldPassword is empty, an error message is displayed.
Ifthe pair of username and oldPassword is not found in the linkedlist, an error message is displayed.
Ifthe username is invalid, an error message is displayed.
bool changeAdminPassword (const char *username, const char *oldPassword, const char *newPassword)
 
displayAdmin

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)
 
freeAdmin

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)
 

Variables

AdminadminHead = NULL
 Admin head pointer.
 

Detailed Description

Admin manager source file.

This file contains the implementation of the admin manager module.

Author
CrimsonCare Team
Date
2025-01-18

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.

Function Documentation

◆ addAdmin()

bool addAdmin ( const char * username,
const char * password,
const char * currentAdminUsername,
const char * currentAdminPassword )

Definition at line 240 of file admin_manager.c.

◆ adminExists()

bool adminExists ( const char * username)

Definition at line 151 of file admin_manager.c.

◆ changeAdminPassword()

bool changeAdminPassword ( const char * username,
const char * oldPassword,
const char * newPassword )

Definition at line 380 of file admin_manager.c.

◆ deleteAdmin()

bool deleteAdmin ( const char * username,
const char * currentAdminUsername,
const char * currentAdminPassword )

Definition at line 306 of file admin_manager.c.

◆ displayAdmin()

void displayAdmin ( void )

Definition at line 422 of file admin_manager.c.

◆ freeAdmin()

void freeAdmin ( void )

Definition at line 441 of file admin_manager.c.

◆ loadAdminCredentials()

void loadAdminCredentials ( void )

Definition at line 96 of file admin_manager.c.

◆ saveAdminCredentials()

void saveAdminCredentials ( void )

Definition at line 54 of file admin_manager.c.

◆ validateAdmin()

bool validateAdmin ( const char * username,
const char * password )

Definition at line 190 of file admin_manager.c.

Variable Documentation

◆ adminHead

Admin* adminHead = NULL

Admin head pointer.

This pointer is used to track admin linkedlist on runtime.

Definition at line 37 of file admin_manager.c.