#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
FILE *fin;
FILE *fout;
char user_name[65535];
void gotoxy(short,short);
COORD getxy();
void theme();
void Login();
int main()
{
Login();
return 0;
}
void theme()
{
}
void Login()
{
puts("\t\t\t1.Login / 2.register\n\n\n\t\t\t input \"1\" or \"2\"");
char ch=_getch();
if(ch=='2')
{
fclose(fin);
printf("\t\t\t\t\tregister\n");
char s[65535];
bool flag;
do
{
flag=true;
printf("Please Input Your User Name By Letter, Underline or Number\n");
scanf("%s",&s);
for(int i=0;i<strlen(s);i++)
flag=flag and ((s[i]>64 and s[i]<91) or (s[i]>47 and s[i]<58) or (s[i]>96 and s[i]<123) or s[i]=='_');
}while(!flag);
if((fin=fopen(s,"rb"))!=NULL)
{
MessageBox(NULL,"The name is in use","From the app",MB_ICONSTOP);
system("CLS");
Login();
exit(0);
}
printf("Set Your Password:\n");
char pwd[65535]="";
char ch;
while((ch=_getch())!='\r')
{
if(ch=='\b' and strlen(pwd))
{
pwd[strlen(pwd)-1]=0;
COORD console=getxy();
gotoxy(console.X-1,console.Y);
putchar(' ');
gotoxy(console.X-1,console.Y);
}
else if(ch!='\b')
{
putchar('*');
pwd[strlen(pwd)]=ch;
}
}
for(int i=0;i<strlen(pwd);i++)
if(pwd[i]<48)
{
MessageBox(NULL,"This String Cannot Be Your Password. ","From the app",MB_ICONSTOP);
system("CLS");
Login();
exit(0);
}
printf("\nPlease Confirm Your Password:\n");
char str[65535];
scanf("%s",&str);
if(strlen(str)!=strlen(pwd))
{
MessageBox(NULL,"The operation failed. ","From the app",MB_ICONSTOP);
system("CLS");
Login();
exit(0);
}
for(int i=0;i<strlen(str);i++)
if(str[i]!=pwd[i])
{
MessageBox(NULL,"The operation failed. ","From the app",MB_ICONSTOP);
system("CLS");
Login();
exit(0);
}
fout=fopen(s,"wb");
fprintf(fout,"%s\n%s\n",s,pwd);
fclose(fout);
MessageBox(NULL,"The operation succeeded! ","From the app",MB_ICONINFORMATION);
sprintf(user_name,"%s",&s);
theme();
}
else if(ch=='1')
{
fclose(fin);
char user[65535],true_pwd[65535],s[65535],pwd[65535];
printf("\t\t\t\t\tLogin\nUser Name:");
scanf("%s",&s);
if((fin=fopen(s,"rb"))==NULL)
{
MessageBox(NULL,"No Such User Here. ","From the app",MB_ICONSTOP);
system("CLS");
Login();
exit(0);
}
fscanf(fin,"%s%s",user,true_pwd);
fclose(fin);
if(strlen(user)!=strlen(s))
{
MessageBox(NULL,"No Such User Here. ","From the app",MB_ICONSTOP);
system("CLS");
Login();
exit(0);
}
for(int i=0;i<strlen(user);i++)
if(user[i]!=s[i])
{
MessageBox(NULL,"No Such User Here. ","From the app",MB_ICONSTOP);
system("CLS");
Login();
exit(0);
}
printf("password: ");
char ch;
while((ch=_getch())!='\r')
{
if(ch=='\b' and strlen(pwd))
{
pwd[strlen(pwd)-1]=0;
COORD console=getxy();
gotoxy(console.X-1,console.Y);
putchar(' ');
gotoxy(console.X-1,console.Y);
}
else if(ch!='\b')
{
putchar('*');
pwd[strlen(pwd)]=ch;
}
}
if(strlen(pwd)!=strlen(true_pwd))
{
MessageBox(NULL,"The operation failed. ","From the app",MB_ICONSTOP);
system("CLS");
Login();
exit(0);
}
for(int i=0;i<strlen(pwd);i++)
if(pwd[i]!=true_pwd[i])
{
MessageBox(NULL,"The operation failed. ","From the app",MB_ICONSTOP);
system("CLS");
Login();
exit(0);
}
MessageBox(NULL,"The operation succeeded! ","From the app",MB_ICONINFORMATION);
sprintf(user_name,"%s",&s);
theme();
}
else
{
MessageBox(NULL,"Wrong Code","From the app",MB_ICONSTOP);
system("CLS");
Login();
exit(0);
}
}
void gotoxy(short x, short y)
{
COORD coord={x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
COORD getxy()
{
HANDLE hStdout;
CONSOLE_SCREEN_BUFFER_INFO pBuffer;
hStdout=GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hStdout,&pBuffer);
return pBuffer.dwCursorPosition;
}