AuthNinja is a secure authentication system implemented in C++. The project follows SOLID principles to ensure a clean and maintainable codebase.
- The user provides a username and password.
- The system checks if the password is strong:
- At least 8 characters.
- Includes uppercase, lowercase, digits, and special characters.
- A unique salt is generated using
CryptoPP::AutoSeededRandomPool
. - The password is combined with the salt and hashed using
CryptoPP::SHA256
. - The username, hashed password (in hex), and salt (in hex) are stored in
users.txt
.
- The user provides their username and password.
- The system retrieves the stored salt and hashed password from
users.txt
. - The entered password is combined with the salt and hashed using
CryptoPP::SHA256
. - The new hash is compared to the stored hash.
- If they match, the login is successful.
- The user provides a new password.
- A new salt is generated using
CryptoPP::AutoSeededRandomPool
. - The new password is combined with the new salt and hashed using
CryptoPP::SHA256
. - The updated hash and salt (in hex) are stored in
users.txt
.
- Each password is hashed with a unique salt, ensuring that even identical passwords produce different hashes.
- This prevents rainbow table attacks.
- Passwords are hashed using SHA-256, a secure and widely trusted algorithm.
- Hashing makes it computationally infeasible to reverse-engineer the original password.
- Hashes and salts are stored in hexadecimal format, ensuring accurate and readable storage in text files.
The program uses the Crypto++ library for:
- Generating secure random salts (
CryptoPP::AutoSeededRandomPool
). - Hashing passwords with SHA-256 (
CryptoPP::SHA256
). - Encoding and decoding data in hexadecimal format (
CryptoPP::HexEncoder
andCryptoPP::HexDecoder
). - Crypto++ ensures the program adheres to industry-standard cryptographic practices.
-
Single Responsibility Principle (SRP):
- Each class has a single responsibility:
Hashing
: Handles password hashing and salt generation.FileHandler
: Manages file operations (storing and retrieving user data).UserRegistration
: Handles user registration logic.UserLogin
: Handles user login logic.PasswordVerification
: Handles password verification logic.
- This ensures that each class is focused on one task, making the code easier to maintain and extend.
- Each class has a single responsibility:
-
Open/Closed Principle (OCP):
- The system is open for extension but closed for modification:
- New hashing algorithms can be added to the
Hashing
class without modifying existing code. - New file storage formats can be added to the
FileHandler
class without affecting other modules.
- New hashing algorithms can be added to the
- This allows the system to evolve without breaking existing functionality.
- The system is open for extension but closed for modification:
-
Liskov Substitution Principle (LSP):
- Derived classes (e.g.,
Hashing
) can be substituted for their base classes without altering the correctness of the program:- If a new hashing algorithm is implemented, it can replace the existing one without affecting other modules.
- This ensures that the system remains robust and flexible.
- Derived classes (e.g.,
-
Interface Segregation Principle (ISP):
- Interfaces are segregated to ensure that classes only implement methods they need:
Hashing
only provides methods for hashing and salt generation.FileHandler
only provides methods for file operations.
- This prevents classes from being forced to implement unnecessary methods.
- Interfaces are segregated to ensure that classes only implement methods they need:
-
Dependency Inversion Principle (DIP):
- High-level modules (e.g.,
UserRegistration
,UserLogin
,PasswordVerification
) depend on abstractions (e.g.,Hashing
,FileHandler
) rather than concrete implementations:- This allows the system to be more flexible and easier to test, as dependencies can be mocked or replaced.
- High-level modules (e.g.,
This code is designed to run on Microsoft Visual Studio. Follow these steps to set up and run the application:
- Clone the repository.
- Clone the Crypto++ library:
git clone https://github.com/weidai11/cryptopp
- Open the
cryptlib.vcxproj
file in Microsoft Visual Studio. - Select the
cryptlib
solution with the Release option and build it. - Once the build is successful, locate the
cryptlib.lib
file undercryptopp\x64\Output\Release
. - Copy the AuthNinja code into a new Microsoft Visual Studio C++ project.
- Open Solution Explorer, right-click on the project, and open Properties.
- Configure the project as follows:
- Select All Configurations and All Platforms at the top bar.
- Under C/C++ > General, set Additional Include Directories to the path of the
cryptopp
directory. - Under Linker > General, set Additional Library Directories to
cryptopp\x64\Output\Release
. - Under Linker > Input, add
cryptlib.lib
to Additional Dependencies. - Under C/C++ > Code Generation, set Runtime Library to Multi-threaded.
- Click Apply, then OK.
- Select the Release option and run the application.
The project includes a GitHub Actions workflow to automate testing on every push or pull request to the main
branch.
- Eya Abidi
- Ines Jabri
- Ahmed Dhia Dridi
- Amina Jebari
- Mohamed Yessine Aifa