A console-based Login and Registration System developed in C++ as part of the CodeAlpha C++ Programming Internship β Task 2.
The application provides a simple user authentication workflow where users can create an account, register a username and password, and later log in using their saved credentials. User information is stored in a local text file and checked during authentication.
The Login & Registration System is designed to demonstrate the basic concepts behind user registration and authentication using C++.
The system allows users to:
- Register a new username and password
- Validate usernames and passwords
- Detect duplicate usernames
- Store registered credentials in a local file
- Log in using previously registered credentials
- Receive success and error messages
- Exit the application through a simple menu
The project also includes a colored console interface and sound feedback for successful and unsuccessful operations.
Internship: CodeAlpha C++ Programming Internship Task: Task 2 β Login and Registration System Language: C++ Application Type: Console Application Platform: Windows
Users can create an account by providing:
- Username
- Password
The registration process checks the entered information before saving the credentials.
A username:
- Cannot be empty
- Can contain letters
- Can contain numbers
- Can contain underscores (
_) - Cannot contain spaces
- Cannot contain other special characters
Example of a valid username:
Maira_123
Before creating a new account, the program checks users.txt to determine whether the username already exists.
If the username is already registered, the user is asked to choose another one.
The program requires passwords to contain at least 6 characters.
Minimum password length: 6 characters
During login, the system:
- Takes the username.
- Takes the password.
- Opens the credentials file.
- Searches for a matching username and password.
- Displays the appropriate result.
The program uses Windows Beep() functionality to provide different sounds for:
- Successful operations
- Errors
The application uses colored console text to distinguish:
- Menu options
- Input prompts
- Success messages
- Error messages
- Section headings
βββββββββββββββββββββββ
β Start β
ββββββββββββ¬βββββββββββ
β
βΌ
βββββββββββββββββββββββ
β Main Menu β
ββββββββββββ¬βββββββββββ
β
βββββββββββββββΌββββββββββββββ
βΌ βΌ βΌ
Register Login Exit
β β
βΌ βΌ
Validate Username Enter Credentials
β β
βΌ βΌ
Check Duplicate Read users.txt
β β
βΌ βΌ
Validate Password Verify Credentials
β β
βΌ βββββββ΄ββββββ
Save to File β β
β Match No Match
β β β
βΌ βΌ βΌ
Registration Success Error
Successful
Registered credentials are stored locally in:
users.txt
The program writes each username and password as a pair separated by a space.
Example structure:
username1 password123
username2 mypass456
During login, the program reads the stored username and password pairs and compares them with the credentials entered by the user.
This project is intended as an educational authentication system.
The current implementation stores passwords in plain text inside users.txt. Therefore, it should not be considered suitable for real-world authentication or production use.
A production-ready authentication system should use techniques such as:
- Password hashing
- Salting
- Secure credential storage
- Encrypted communication
- Strong authentication policies
- Proper access control
This project focuses on demonstrating the basic C++ implementation of registration, file handling, validation, and login verification.
The program is organized into separate functions for different responsibilities.
Checks whether the username follows the allowed character rules.
bool validUsername(string username)Checks whether the password meets the minimum length requirement.
bool validPassword(string password)Searches users.txt to determine whether a username is already registered.
bool usernameExists(string username)Handles the complete registration process, including validation and saving the new credentials.
void registration()Reads stored credentials and verifies the user's login information.
void login()Changes the Windows console text color.
void setColor(int color)Provide audio feedback for successful and unsuccessful actions.
C++
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <windows.h>- Functions
- Strings
- File handling
- Input validation
- Loops
- Conditional statements
- Boolean functions
- Character validation
- File streams
- Console formatting
- Windows API functions
When the program starts, the user is presented with:
========================================
LOGIN & REGISTRATION SYSTEM
========================================
1. Register
2. Login
3. Exit
Enter choice:
The user can select one of the three available operations.
The registration workflow is:
Enter Username
β
Validate Username
β
Check Existing Username
β
Enter Password
β
Validate Password
β
Save Credentials
β
Registration Successful
If an invalid username or password is entered, the program displays an appropriate error message and asks for valid information.
The login workflow is:
Enter Username
β
Enter Password
β
Open users.txt
β
Search Stored Credentials
β
ββββ΄βββ
β β
Match No Match
β β
Success Error
When the credentials match a registered account, the program displays:
Login successful!
Welcome, username!
Otherwise, the user receives an invalid credentials message and can try again.
The program handles several invalid situations, including:
- Empty or invalid usernames
- Unsupported username characters
- Duplicate usernames
- Passwords shorter than 6 characters
- Invalid menu selections
- Non-numeric menu input
- Missing
users.txt - File opening errors during registration
Error messages are displayed using a different console color and an error sound.
CodeAlpha_LoginAndRegistrationSystem/
βββ 1. Screenshot.jpg
βββ 2. Screenshot.jpg
βββ 3. Screenshot.jpg
βββ 4. Screenshot.jpg
βββ README.md
βββ main.cpp
users.txtis created/updated by the program when users register. It contains the locally stored credentials used by the application.
To compile and run this project:
- Windows operating system
- C++ compiler
- C++ compatible IDE
- Support for Windows API
The project uses:
#include <windows.h>for console colors, delays, and sound effects.
git clone https://github.com/MairaAdil/CodeAlpha_LoginAndRegistrationSystem.gitOpen main.cpp in a C++ compatible IDE such as Visual Studio, Code::Blocks, or another Windows-based C++ development environment.
Build/compile the C++ source file.
Start the program and choose:
1 β Register
2 β Login
3 β Exit
========================================
REGISTRATION
========================================
Enter username: Maira_123
Enter password: password123
Registration successful!
========================================
LOGIN
========================================
Enter username: Maira_123
Enter password: password123
Login successful!
Welcome, Maira_123!
Invalid username or password!
Please try again.
This project provided practical experience with:
- Building a menu-driven C++ application
- Implementing registration logic
- Implementing login verification
- Working with text files
- Reading and writing file data
- Validating user input
- Detecting duplicate usernames
- Creating reusable functions
- Using Boolean validation functions
- Working with Windows console features
- Designing a basic authentication workflow
The system could be further enhanced by adding:
- Password hashing
- Salted password storage
- Password masking during input
- Stronger password requirements
- Password recovery
- Account deletion
- Username/password update
- Login attempt limits
- User-specific files or a database
- Encrypted credential storage
- Session management
- Multi-user roles and permissions
- More secure authentication mechanisms
This application was created as an educational C++ project for the CodeAlpha Internship.
It demonstrates the fundamental workflow of registration and login using local file storage. It is not intended to replace a production authentication system.
Maira Adil
BS Artificial Intelligence Student University of Central Punjab
- LinkedIn: linkedin.com/in/mairaadil
- GitHub: github.com/MairaAdil
This project was completed as Task 2 β Login and Registration System during the CodeAlpha C++ Programming Internship.
The project helped strengthen practical understanding of C++ functions, file handling, validation, and basic authentication workflows.
Special thanks to CodeAlpha for providing the internship opportunity and project-based learning experience to practice and apply C++ programming concepts.
β If you found this project useful, feel free to explore the repository and leave a star.