Login And Registration System In C++ | C++ Project

by | Dec 10, 2022 | C/C++, Coding

Home » Coding » Login And Registration System In C++ | C++ Project

Introduction

In this coding project, we will create a Login And Registration System In C++. The basic functionality of this project in C++ is to help register the user, and then once the user has been registered, the system will validate the details entered by the user to help them log in. This helps us connect the users to the websites and many more applications with the legal and authenticated process.

 

Objectives

As far as the objective of building a Login And Registration System In C++ is concerned. We have two main objectives

  • To help the user to enter the details so that he/she can be registered in with the legitimate process and the user’s information gets stored in the database
  • Once the user is registered, then the users need to enter his/her name with a valid password so that no unwanted users can access the sites or the applications. And only registered users can access the application and its features.

Requirements

Source Code

#include<iostream>
#include<string>
#include <stdlib.h>
#include <fstream>
using namespace std;
void mainmenu();
int choice;
bool cinfail;
int confirmation;
string username, password, password2;
void writetofile(string username){
ofstream writefile;
string file = username+".txt";
writefile.open(file.c_str());
writefile << password;
writefile.close();
mainmenu(); }
void login(){
cout << "You are being logged in!";}
void registerpassword(){
cout << "Please enter the password:" << endl;
cin >> password;
cout << "Please renter your password:" << endl;
cin >> password2;
if (password == password2){
cin.clear();
cin.ignore(10000,'\n');
writetofile(username);
exit(1);
}
else;{
cout << "Sorry invalid" << endl;
registerpassword();
}}
void registerme(){
cout << "Please enter your username: " << endl;
getline(cin, username);
cout << "\nUsername - \""<< username << "\"\nConfirm? \n\n[1] Yes\n[2] No" << endl;
cin >> confirmation;
if (confirmation == 1){
registerpassword();
}
else; {
cout << "Sorry invalid input, Please try again" << endl;
cin.clear();
cin.ignore(10000,'\n');
registerme();
}}
void exit(){
exit(0);}
void mainmenu(){ cout << "Hello, Would you like to log in or register\n[1] Login\n[2] Register\n[3] Exit" <<endl; cin >> choice; do{
cinfail = cin.fail();
cin.clear();
cin.ignore(10000,'\n');
}while(cinfail == true);{
switch(choice){
case 1:
login();
break;
case 2:
registerme();
break;
case 3:
exit();}}}
main(){
cout<<"\n";
cout<<"WELCOME----TO----LOGIN----REGISTRATION----SYSTEM"<<endl;
cout<<"\n";
mainmenu();
}

Explanation Of The Code

1. Initially, we have included all the necessary libraries which will be needed to build this Login And Registration System In C++. Then we created different functions which are responsible for performing different operations and implementations accordingly.

2. Through the concept of files, we have added the information of the user that he/she entered to get into the registration state.

3. After that, we have included the fstsream header file in our code so that all the files related operations can be performed accordingly and we have access to all the file functions present in C++.

4. Next, we have asked to give the options to the user to log in, register, or exit, which makes our program a menu-driven program, and the user can perform the operations according to his need by selecting one of the options.

5. According to the choice entered by the user, that particular function is called, and the functionalities are achieved accordingly.

Hence the operations are performed, and our program terminates.

Output

Login and Registration System in C++

Conclusion

Hence we have successfully built this Login And Registration System In C++ in which the user needs to enter the details for the registration process, and then the user is allowed to log in to the application accordingly. This is a strong, robust C++ application that helps the user log in to the particular server by entering all the relevant details.

 

More C++ Projects>>>>

You May Also Like To Create…