1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
#include <iostream>
#include <conio.h>
#include <string>
#include <cstdlib>
using namespace std;
string pw()
{ string pass,length;
int cnt;
char z;
cout << " enter password: ";
pass="";
while (z!=13)
{
z=getch();
pass+=z;
if (z==8)
{
cout<<'\b'<<" "<<'\b';
if (pass.length()<0)
{
continue;
}
}
else if (z==13)
{
break;
cin.ignore();
}
else{cout<<"*";}
}
return pass;
}
string b()
{string logpass;
char w;
cout << "Enter password: ";
logpass="";
while (w!=13)
{
w=getch();
logpass+=w;
if (w==8)
{
cout<<'\b'<<" "<<'\b';
}
else if (w==13)
{
break;
cin.ignore();
} else{cout<<"*";}
}
cout<<endl;
return logpass;
}
int main ()
{
string user,password, x,y,count;
char p;
int length,acc=1,hasup,haslow,hasalpha;
int ctr = 0;
cout<<"You must first create an account"<<endl;
system("pause");
system("cls");
while (acc!=0)
{
cout<<"SIGN-UP FOR AN ACCOUNT"<<endl;
cout << "Enter username: ";
getline(cin,x);
y=pw();
length=y.length()-1;
//cout<<length;
if (length>=6&&length<=10)
{ char v[length];
int i;
for (int i = 0; i < length; i++)
{ v[i]=y[i];
}
hasup=0;
haslow=0;
hasalpha=0;
for (int i = 0; i < length and v[i]; i++)
{if (isupper(v[i]))
{hasup=1;}
else if (islower(v[i]))
{haslow=1;}
if (isalpha(v[i]))
{hasalpha=1;}
}
}if (haslow==1 && hasup==1 &&hasalpha==1)
{
cout<< "Sign in successful!"<<endl;
acc=0;
system("pause");
system("cls");
}
else
{
cout<<"Password should have at least 1 uppercase and lowercase letter, 1 digit and 6 to 10 characters."<<endl;
system("pause");
system("cls");
}
}
string cun,logpass,z;
while (cun!=x && z!=y)
{
cout<<"LOG IN TO YOUR ACCOUNT"<<endl;
cout<<"Enter username: ";
getline(cin,cun);
z=b();
if (cun!=x ||z!=y)
{
cout<<"Invalid username or password"<<endl;
system("pause");
system("cls");
}
else{
continue;
}
}
cout<<"WELCOME TO CEA"<<endl<<"You are now logged in! "<<endl<<"ENJOY YOUR FREE STAY"<<endl;
system("pause");
system("cls");
return 0;
}
|