當前位置:編程學習大全網 - 編程語言 - 多用戶登錄系統C語言程序

多用戶登錄系統C語言程序

#include?<stdio.h>

#include?<stdlib.h>

#include?"string.h"

#include?"windows.h"

int?total=0;

struct?u_p

{

char?user[20];

char?pass[20];

}?s[50];

void?read()

{

total=GetPrivateProfileInt("INFO","count",0,"d:\\Info.dat");

int?i;

char?t[5]={"\0"};

for(i=0;i<total;i++)

{

sprintf(t,"%d",i+1);

GetPrivateProfileString(t,"USER","",s[i].user,20,"d:\\Info.dat");

GetPrivateProfileString(t,"PASSWORD","",s[i].pass,20,"d:\\Info.dat");

}

}

void?input()

{

int?p,i=0,count=0,f_u=0,f_p=0;

char?user[20]={"\0"};

char?password[20]={"\0"};

while(1)

{

f_u=0;

f_p=0;

system("cls");

printf("當前***有%d個註冊用戶",total);?

printf("\n\n請輸入用戶名:");

memset(user,'\0',20);

scanf("%s",user);

printf("\n請輸入密碼:");

memset(password,'\0',20);

i=0;

while(1)

{

p=_getch();

if(p==10?||?p==13)

{

break;

}

password[i++]=p;

printf("*");

}

for(i=0;i<total;i++)

{

if(strcmp(s[i].user,user)==0)

{

f_u=1;

if(strcmp(s[i].pass,password)==0)

{

f_p=1;

printf("\n\n歡迎?%s",user);

fflush(stdin);

_getche();

continue;

}

}

}

if(f_u==0)

{

printf("\n\n不存在該用戶名!?選?1?重新輸入,選?2?註冊新用戶");

int?c=0;

fflush(stdin);

c=_getche();

if(c=='1')

{

continue;

}

else?if(c=='2')

{

system("cls");

printf("註冊新用戶");

printf("\n\n\n請輸入用戶名:");

memset(user,'\0',20);

scanf("%s",user);

printf("\n請輸入密碼:");

char?temp[20]={"\0"}?;

i=0;

while(1)

{

p=_getch();

if(p==10?||?p==13)

{

break;

}

temp[i++]=p;

printf("*");

}

printf("\n請再次輸入密碼:");

i=0;

memset(password,'\0',20);

while(1)

{

p=_getch();

if(p==10?||?p==13)

{

break;

}

password[i++]=p;

printf("*");

}

if(strcmp(temp,password)==0)

{

total++;

char?t[5]={"\0"};

sprintf(t,"%d",total);

WritePrivateProfileString("INFO","count",t,"d:\\Info.dat");

WritePrivateProfileString(t,"USER",user,"d:\\Info.dat");

WritePrivateProfileString(t,"PASSWORD",password,"d:\\Info.dat");

printf("\n\n註冊成功,請重新登錄");

fflush(stdin);

_getch();

count=0;

read();

continue;?

}

else

{

printf("\n\n兩次密碼不壹致,註冊失敗");

fflush(stdin);

_getch();

count=0;

continue;?

}

}

}

else?if(f_p==0)

{

count++;?

if(count>=3)

{

printf("\n\n連續輸入3次錯誤,程序將退出");

fflush(stdin);

_getche();

return?;?

}

printf("\n\n密碼輸入錯誤,請重新輸入");

fflush(stdin);

_getche();

}

}

return?;

}

int?main(int?argc,?char?*argv[])?

{

read();

input();

return?0;

}

  • 上一篇:LOGO社團活動策劃
  • 下一篇:蘋果電腦適合什麽人用
  • copyright 2024編程學習大全網