// 登录界面   第一次可设置密码   之后的登录要输入密码进行验证    密码长度8~12

#include<stdio.h>

#include<ctype.h>

#include<conio.h>

#include<string.h>

#include<stdlib.h>

#include<Windows.h>

#define LEN 12





static int count=0;

int main(){

char password[LEN+1];

memset(password,NULL,LEN+1);

char ch;

if(count==0){

loop_passwordSet:printf("this is your first time to login,pls set your password.\n");

printf("the length of password has a length between 8~12 without any nonprint charators.\n");

int inputLength=0;

ch=getch();


while(isprint(ch)){

if(ch!=' '){

putchar('*');

password[inputLength]=ch;

inputLength++;

ch=getch();

}

if(!isprint(ch))

break;

if(inputLength==LEN)

break;

}

printf("\n");

printf("what you have just input is: %s\n",password);

printf("Press Y/N to confirm.\n");

ch=getch();

switch(ch){

case 'Y' :{

printf("password set completed!\n");

count=1;

break;

}

case 'y' :{

printf("password set completed!\n");

count=1;

break;

}

case 'N': {

printf("password set canceled.\n");

goto loop_passwordSet;

}

case 'n': {

printf("password set canceled.\n");

goto loop_passwordSet;

}


default: {

printf("invalid input,pls try again.\n");

goto loop_passwordSet;

}

}

}

if(count==1){

char toMatchPassword[LEN+1];

memset(toMatchPassword,NULL,LEN+1);

int toMatchLength=0;

loop_inputPassword:
printf("input your password to login.\n");

ch=getch();


while(isprint(ch)){

if(ch!=' '){

putchar('*');

toMatchPassword[toMatchLength]=ch;

ch=getch();

toMatchLength++;


}

if(!isprint(ch)){

break;

}

if(toMatchLength==LEN){

break;

}

}

if(strcmp(password,toMatchPassword)==0){

printf("password Correct! LOGIN SUCCESS!\n");

printf("**********************\n");

printf("**********************\n");

printf("** WELCOME **\n");

printf("**********************\n");

printf("**********************\n");

printf("*********** By ZHAOs*\n");

Sleep(2000);

}

if(strcmp(password,toMatchPassword)!=0){

printf("Password input error! Press Y to try again!\n");

char ch=getch();

switch(ch){

case 'Y':{

goto loop_inputPassword;


}

case 'y':{

goto loop_inputPassword;


}

case 'N':{

exit(0);

}

case 'n':{

exit(0);

}

default:

{

printf("invalid input, now the system would abort....\n");

Sleep(2000);

exit(0);

}

}

}

}



system("pause");

return 0;

}