Skip to content

About

A console-based Login & Registration System developed in C++ for the CodeAlpha Internship, featuring user registration, username validation, duplicate detection, password masking, file-based credential storage, and login verification.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

ย 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” Login & Registration System โ€” CodeAlpha Internship

C++ Programming Internship โ€” Task 2

A console-based Login and Registration System developed in C++ as part of the CodeAlpha C++ Programming Internship.

The application allows users to create accounts, validates registration information, prevents duplicate usernames, stores account credentials in a local file, and verifies user credentials during login.


๐Ÿ“Œ Project Overview

The Login & Registration System is a simple authentication application designed to demonstrate fundamental C++ programming concepts through a practical user-management system.

The program provides two main operations:

  • User Registration
  • User Login

During registration, the application validates the username and password before saving the account information to a local users.txt file.

During login, the program reads the stored credentials and compares them with the information entered by the user.


๐ŸŽฏ Internship Task

This project was completed as Task 2: Login and Registration System for the CodeAlpha C++ Programming Internship.

Task Requirements

The internship task required the application to:

  • Create a registration function that accepts username and password.
  • Validate user inputs.
  • Check for duplicate usernames.
  • Store user credentials in a file.
  • Implement a login function.
  • Read stored credentials and verify the user's identity.
  • Display appropriate success or error messages.

This implementation fulfills these requirements with additional input validation, password confirmation, hidden password input, exception handling, and a menu-driven console interface.


โœจ Features

๐Ÿ‘ค User Registration

Users can create a new account by providing:

  • Username
  • Password
  • Password confirmation

The system checks the provided information before creating the account.

๐Ÿ”Ž Username Validation

The username must:

  • Contain at least 3 characters
  • Contain only letters, numbers, and underscores

Examples of valid usernames:

sultan
sultan123
sultan_01
user2026

Invalid characters such as spaces and special symbols are rejected.

๐Ÿšซ Duplicate Username Detection

Before registering a new account, the program searches the existing users.txt file.

If the username already exists, registration is rejected.

Error: This username is already registered.

๐Ÿ”‘ Password Validation

The system requires passwords to contain at least 6 characters.

The | character is also rejected because it is used as the separator between usernames and passwords in the database file.

๐Ÿ‘๏ธ Hidden Password Input

Passwords are not displayed directly while being entered.

Instead, each typed character is represented by:

*

The program also supports Backspace while entering passwords.

๐Ÿ” Password Confirmation

During registration, users must enter their password twice.

If both passwords do not match, registration is cancelled.

Error: Passwords do not match.

๐Ÿ’พ File-Based User Storage

Registered accounts are stored in:

users.txt

Each record follows this format:

username|password

For example:

sultan123|MyPassword123
ali_01|HelloWorld

๐Ÿ”“ Login Verification

During login, the system:

  1. Reads the entered username.
  2. Reads the entered password.
  3. Opens users.txt.
  4. Searches through the stored records.
  5. Compares the entered credentials with saved credentials.
  6. Displays an appropriate result.

Successful login:

Login successful. Welcome, sultan123!

Failed login:

Login failed. Incorrect username or password.

๐ŸŽจ Colored Console Interface

The program uses Windows console colors to improve readability.

Different colors are used for:

  • Titles
  • Borders
  • User prompts
  • Menu options
  • Success messages
  • Error messages
  • User input

๐Ÿ–ฅ๏ธ Main Menu

When the program starts, users are presented with:

==========================================================
              LOGIN & REGISTRATION SYSTEM
==========================================================

  [1] Register New User
  [2] Login
  [3] Exit

Enter your choice:

๐Ÿ”„ Registration Workflow

                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚   Start Program      โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                             โ–ผ
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚   Select Register    โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                             โ–ผ
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚   Enter Username     โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                             โ–ผ
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Validate Username    โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                    Valid? โ”€โ”€โ”ดโ”€โ”€ No
                             โ”‚
                             โ–ผ
                    Display Error
                             โ”‚
                             โ”‚ Yes
                             โ–ผ
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Check Duplicate      โ”‚
                  โ”‚ Username             โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                    Exists? โ”€โ”ดโ”€ Yes
                             โ”‚
                             โ–ผ
                    Display Error
                             โ”‚
                             โ”‚ No
                             โ–ผ
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Enter Password       โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                             โ–ผ
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Validate Password    โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                             โ–ผ
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Confirm Password     โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                             โ–ผ
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Save Account to      โ”‚
                  โ”‚ users.txt            โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                             โ–ผ
                  Registration Successful

๐Ÿ”„ Login Workflow

                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚    Select Login      โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                             โ–ผ
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Enter Username       โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                             โ–ผ
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Enter Password       โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                             โ–ผ
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Open users.txt       โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                             โ–ผ
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Read Stored          โ”‚
                  โ”‚ Credentials          โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                             โ–ผ
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Compare Username &   โ”‚
                  โ”‚ Password             โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                    Match? โ”€โ”€โ”ดโ”€โ”€ No
                             โ”‚
                             โ–ผ
                    Login Failed
                             โ”‚
                             โ”‚ Yes
                             โ–ผ
                    Login Successful

๐Ÿ› ๏ธ Technologies Used

  • C++
  • File Handling
  • Windows API
  • Console Application
  • Standard C++ libraries

Libraries Used

#include <iostream>
#include <fstream>
#include <string>
#include <stdexcept>
#include <cctype>
#include <conio.h>
#include <windows.h>

๐Ÿ’ป C++ Concepts Demonstrated

This project demonstrates several important C++ programming concepts.

Functions

The program is divided into reusable functions, including:

setColor()
clearScreen()
printLine()
printTitle()
pauseScreen()
readPassword()
isValidUsername()
usernameExists()
registerUser()
loginUser()

This keeps the program organized and separates different responsibilities.


File Handling

The application uses:

ifstream
ofstream

to read and write user account information.

Registration appends new users to:

users.txt

Login reads the same file to verify credentials.


String Manipulation

The program uses string operations for:

  • Username processing
  • Password handling
  • Searching for the | separator
  • Extracting stored usernames
  • Extracting stored passwords

For example:

string savedUsername = line.substr(0, separatorPosition);
string savedPassword = line.substr(separatorPosition + 1);

Input Validation

The program validates:

  • Username length
  • Username characters
  • Duplicate usernames
  • Password length
  • Password confirmation
  • Reserved separator characters
  • Menu selections

Exception Handling

The program uses:

try
catch
throw

to handle file-related errors and prevent unexpected program termination.

For example, if the user database cannot be opened, the program reports an appropriate error.


Character Handling

The program uses character validation through:

isalnum()

to ensure usernames contain only permitted characters.


Console Input Control

The project uses:

_getch()

from <conio.h> to:

  • Hide password characters
  • Display * instead
  • Detect Enter
  • Handle Backspace
  • Pause the application

Windows Console API

The program uses:

SetConsoleTextAttribute()

through <windows.h> to create a colored console interface.


๐Ÿ“‚ Data Storage

The application uses a local text file named:

users.txt

The storage format is:

username|password

Example:

sultan123|Password123
maira_01|Hello123
student2026|CppProject

The | character separates the username and password.

The program therefore prevents users from including | in their passwords.


๐Ÿ” Security Considerations

This project demonstrates the basic structure of an authentication system for educational purposes.

It includes:

  • Password masking during input
  • Password confirmation
  • Minimum password length
  • Username validation
  • Duplicate username prevention
  • Credential verification
  • File-access error handling

โš ๏ธ Important Limitation

The current implementation stores passwords in plain text inside users.txt.

For example:

username|password

This is suitable for demonstrating basic C++ file handling and authentication logic, but it should not be considered production-level credential storage.

A production authentication system should use secure password hashing and appropriate credential-protection mechanisms instead of storing raw passwords.


๐Ÿงช Example Registration

==========================================================
              NEW USER REGISTRATION
==========================================================

Enter username: sultan123
Enter password: ************
Confirm password: ************

Registration successful! You can now log in.

๐Ÿงช Example Login

==========================================================
                    USER LOGIN
==========================================================

Enter username: sultan123
Enter password: ************

Login successful. Welcome, sultan123!

โŒ Example Failed Login

==========================================================
                    USER LOGIN
==========================================================

Enter username: sultan123
Enter password: ********

Login failed. Incorrect username or password.

๐Ÿšซ Example Duplicate Username

Enter username: sultan123

Error: This username is already registered.

๐Ÿ“ Project Structure

CodeAlpha_LoginAndRegistrationSystem/
โ”‚โ”€โ”€ 1. Screenshot.jpg
โ”‚โ”€โ”€ 2. Screenshot.jpg
โ”‚โ”€โ”€ 3. Screenshot.jpg
โ”œโ”€โ”€ 4. Screenshot.jpg
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ main.cpp

users.txt is created/used by the program when account information is stored.


โš™๏ธ Requirements

To compile and run this project, you need:

  • Windows operating system

  • C++ compiler

  • Visual Studio or another compatible C++ IDE/compiler

  • Support for Windows-specific headers such as:

    • windows.h
    • conio.h

The project is designed primarily for a Windows console environment because it uses Windows console APIs and _getch().


๐Ÿš€ How to Run

1. Clone the Repository

git clone https://github.com/5ultaan/CodeAlpha_LoginAndRegistrationSystem.git

2. Open the Project

Open main.cpp in:

  • Visual Studio
  • Code::Blocks
  • Another compatible C++ development environment

3. Compile the Program

Compile main.cpp using a compatible C++ compiler.

4. Run the Application

After launching the program, use the menu:

[1] Register New User
[2] Login
[3] Exit

Register an account first, then use the same credentials to test the login functionality.


๐Ÿ“Œ Project Highlights

This project provides practical experience with:

  • C++ programming
  • Functions
  • File input/output
  • Authentication logic
  • User registration
  • Login verification
  • String processing
  • Input validation
  • Exception handling
  • Password masking
  • Windows console programming
  • Menu-driven applications

๐Ÿ”ฎ Future Improvements

The system could be further improved by adding:

  • Password hashing
  • Encrypted credential storage
  • Stronger password requirements
  • Login attempt limits
  • Account lockout
  • Password recovery
  • User profile management
  • Database integration
  • Multiple user roles
  • Improved cross-platform compatibility
  • A graphical user interface

๐ŸŽ“ Internship Information

Internship: C++ Programming Internship Organization: CodeAlpha Task: Task 2 โ€” Login and Registration System

This project was developed as part of the practical programming tasks assigned during the CodeAlpha C++ Programming Internship.

The task provided practical experience in implementing registration and authentication logic using C++ and file handling.


๐Ÿ‘จโ€๐Ÿ’ป Author

Sultan Shahzad Awan

BS Artificial Intelligence Student University of Central Punjab

Profiles


โญ Acknowledgment

Thanks to CodeAlpha for providing the internship opportunity and project-based learning experience in C++ programming.


๐Ÿ“Œ Repository Information

Repository: CodeAlpha_LoginAndRegistrationSystem

Project: Login & Registration System Language: C++ Internship: CodeAlpha C++ Programming Internship Task: 2

About

A console-based Login & Registration System developed in C++ for the CodeAlpha Internship, featuring user registration, username validation, duplicate detection, password masking, file-based credential storage, and login verification.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages