OOP Microproject.......
(Codeblocks is recommended to perform this Program)
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
class login
{
private:
int c,j;
char u_name[15][20],pass[15][20];
public:
login()
{
c=0;
j=0;
}
void Register()
{
char a[20];
int d,z;
for(;j<=c;j++)
{
cout<<"\nCreating New Account....";
cout<<"\nEnter Username = ";
cin>>a;
for(int k=0;k<c;k++)
{
d=strcmp(u_name[k],a);
if(d==0)
{
z=4;
break;
}
}
if(z==4)
{
cout<<"Entered UserName Already Exist";
c--;
j--;
}
else
{
strcpy(u_name[j],a);
cout<<"\nEnter Password = ";
cin>>pass[j];
}
}
c++;
}
void log()
{
char user[20],upass[20];
int l,d,f;
cout<<"\nEnter Login Details....";
cout<<"\nEnter Username: ";
cin>>user;
cout<<"\nEnter Password: ";
cin>>upass;
for(int i=0;i<c;i++)
{
l=strcmp(user,u_name[i]);
d=strcmp(pass[i],upass);
if(l==0 && d==0)
{
f=4;
}
}
if(f==4)
{
cout<<"\n********************************\n";
cout<<"\nWelcome, "<<user<<"\n";
cout<<"\n********************************\n";
}
else
{
cout<<"\nInvalid Username or Password......";
}
}
void showdata()
{
string pas ="";
char ch;
int d;
cout << "\nEnter Password: ";
ch = _getch();
while(ch != 13)
{//character 13 is enter
pas.push_back(ch);
cout << '*';
ch = _getch();
}
if(pas == "Manav7045")
{
cout << "\nAccess Granted! \n\n";
cout<<"\nUsername\tPassword\n";
for(int i=0;i<c;i++)
{
cout<<"\n"<<u_name[i]<<"\t\t"<<pass[i];
}
}
else
{
cout<<"Wrong Password......TRY AGAIN!!";
}
}
};
int main()
{
login n;
int ch;
do
{
cout<<"\n1: Register\n2: Login\n3: Database\n4:Exit";
cout<<"\nEnter any Choice = ";
cin>>ch;
if (ch==1)
{
n.Register();
}
else if (ch==2)
{
n.log();
}
else if (ch==3)
{
n.showdata();
}
else if(ch==4)
{
cout<<"\nExiting The Program.....";
break;
}
else
{
cout<<"\nWrong Entry.....\n";
ch=0;
}
} while (ch!=4);
getch();
return 0;
}