這個簡單
創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站設(shè)計、網(wǎng)站建設(shè)與策劃設(shè)計,昭通網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)十載,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:昭通等地區(qū)。昭通做網(wǎng)站價格咨詢:13518219792
這就就是加密函數(shù)
int?password()
{
int?n=0,a=0;
char?mi1[80];
int?i=0,a1,a2,a3;
int?index=0,m=0;
char?str[30];
char?user[12];
do{
printf("\n\t************************how?are?you*****************************\n\n\n");
printf("\t\tplease?input?the?username:");
scanf("%s",user);??????????????????
a1=strcmp(user,"20085126");
if(a1==0)
{
FILE?*f1;
if((f1=fopen("1mi.txt","rt"))==NULL)?
{?
printf("Cannot?open?file?strike?any?key?exit!");???????
exit(0);
}
rewind(f1);//重定向文件內(nèi)部指針將文件內(nèi)部的位置指針重新指向一個流(數(shù)據(jù)流/文件)的開頭
fgets(mi1,7,f1);
do{
printf("\n\t\tplease?input?the?password:");
scanf("%s",str);
printf("\n");
if(!strcmp(str,user))??????????????/*比較密碼是否一樣*/
m=1;
index++;
if(index3)
{
printf("\n\t*****************************************************\n\n");
printf("\t\tThe?error?number?is?more?than?three?times?while?input?the?password,?exit?system!\n");
printf("\n\t*****************************************************\n\n\n");
return?0;
}
}while(m==0);
fclose(f1);
}
}
}
睿爾科技
更新學(xué)習(xí)資料
//專門注冊用戶和登錄的代碼
#include?stdio.h
#include?stdlib.h
#include?string.h
#include?stdbool.h
#include?windows.h
typedef?struct
{
int?x;
int?y;
}PT_STRUCT;
typedef?struct
{
char?user[20];
char?pw[20];
}USER_STRUCT;
PT_STRUCT?pt;
bool?LoginSuccess=false;
char?CurrentUser[20]={'\0'};
int?UserCount=0;
USER_STRUCT*?pUser=NULL;
char?WorkDir[100]={'\0'};
char?DataFile[100]={'\0'};
void?setxy(int?x,?int?y)??//設(shè)置光標(biāo)位置?
{
COORD?coord?=?{x,?y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),?coord);
}
void?getxy()?????????????//獲取當(dāng)前光標(biāo)所在位置?
{
HANDLE?hConsole?=?GetStdHandle(STD_OUTPUT_HANDLE);
COORD?coordScreen?=?{0,?0};?//光標(biāo)位置
CONSOLE_SCREEN_BUFFER_INFO?csbi;
if(GetConsoleScreenBufferInfo(hConsole,?csbi))
{
pt.x=csbi.dwCursorPosition.X;
pt.y=csbi.dwCursorPosition.Y;
}
}
void?input(char*?buf)
{
int?len=strlen(buf);
int?c;
int?i=0;
while(1)
{
c=getch();
if(c==8??i==0)
{
continue;
}
if(c==10?||?c==13)?break;
if(c==8??i0)
{
buf[i-1]='\0';
i--;
getxy();
setxy(pt.x-1,pt.y);
printf("?");
setxy(pt.x-1,pt.y);
}
else?if(i=0)
{
printf("*");
buf[i++]=c;
}
if(i=buf)
{
return;
}
}
}
void?GetUserDataFromFile()
{
UserCount=GetPrivateProfileInt("USER","user_count",0,DataFile);
if(pUser!=NULL)
{
free(pUser);
}
pUser=(USER_STRUCT*)malloc(sizeof(USER_STRUCT)*(UserCount+1));
int?i;
char?ch[5];
for(i=0;iUserCount;i++)
{
memset(ch,'\0',5);
sprintf(ch,"%d",i+1);
GetPrivateProfileString(ch,"user","",pUser[i].user,20,DataFile);
GetPrivateProfileString(ch,"pw","",pUser[i].pw,20,DataFile);
}
}
void?WriteDataToFile()
{
int?i;
char?t[5]={"\0"};
sprintf(t,"%d",UserCount);
WritePrivateProfileString("USER","user_count",t,DataFile);
for(i=0;iUserCount;i++)
{
sprintf(t,"%d",i+1);
WritePrivateProfileString(t,"user",pUser[i].user,DataFile);
WritePrivateProfileString(t,"pw",pUser[i].pw,DataFile);
}
GetUserDataFromFile();
}
bool?login()
{
if(LoginSuccess==true)
{
printf("\n當(dāng)前已有用戶登錄!?重新登錄嗎?(Y/N)");
char?sel;
fflush(stdin);
scanf("%c",sel);
if(sel=='y'?||?sel=='Y')
{
LoginSuccess==false;
}
else
{
return?false;
}
}
char?user[20]={'\0'};
char?pw[20]={'\0'};
printf("\nInput?User:?");
fflush(stdin);
scanf("%s",user);
printf("\nInput?Password:?");
fflush(stdin);
input(pw);
bool?find=false;
int?i;
for(i=0;iUserCount;i++)
{
if(strcmp(user,pUser[i].user)==0??strcmp(pw,pUser[i].pw)==0)
{
find=true;
LoginSuccess=true;
strcpy(CurrentUser,pUser[i].user);
break;
}
}
if(find==true)
{
return?1;
}
else
{
return?0;
}
}
bool?regist(char*?ErrBuf)
{
char?user[20]={'\0'};
char?pw1[20]={'\0'};
char?pw2[20]={'\0'};
printf("\nInput?User:?");
fflush(stdin);
scanf("%s",user);
int?i;
for(i=0;iUserCount;i++)
{
if(strcmp(user,pUser[i].user)==0)
{
strcpy(ErrBuf,"User?Repeat");
return?false;
}
}
printf("\nInput?Password:?");
fflush(stdin);
input(pw1);
printf("\nReInput?Password:?");
fflush(stdin);
input(pw2);
if(strcmp(pw1,pw2)!=0)
{
strcpy(ErrBuf,"Password?Differ");
return?false;
}
strcpy(pUser[UserCount].user,user);
strcpy(pUser[UserCount].pw,pw1);
UserCount++;
return?true;
}
int?main()
{
_getcwd(WorkDir,100);?//取得當(dāng)前程序的絕對路徑
strcpy(DataFile,WorkDir);
strcat(DataFile,"\\user.dat");
if(access(DataFile,0))
{
printf("\n用戶數(shù)據(jù)文件不存在,?按任意鍵將創(chuàng)建文件");
getchar();
FILE*?fp;
fp=fopen(DataFile,"wb");
int?re=fputs("[USER]\nuser_count=0",fp);
if(re=0)
{
printf("\n用戶數(shù)據(jù)文件創(chuàng)建成功!");
}
else
{
printf("\n用戶數(shù)據(jù)文件創(chuàng)建失敗!");
}
getchar();
fclose(fp);
}
GetUserDataFromFile();
while(1)
{
system("cls");
printf("已注冊用戶%d\n",UserCount);
if(LoginSuccess==true)
{
printf("Logined?User?:?%s",CurrentUser);
}
printf("\n-------------------------------");
printf("\n登錄---1");
printf("\n注冊---2");
printf("\n退出---3");
printf("\n-------------------------------");
printf("\n\nInput:(1,2,3)?:?");
fflush(stdin);
int?sel;
bool?re;
char?ErrBuf[50]={'\0'};
scanf("%d",sel);
switch(sel)
{
case?1:
re=login();
if(re==true)
{
printf("\nLogin?Success!?Current?User:?%s",CurrentUser);
fflush(stdin);
getchar();
}
else
{
printf("\nLogin?Fail!");
fflush(stdin);
getchar();
}
break;
case?2:
memset(ErrBuf,'\0',50);
re=regist(ErrBuf);
if(re!=true)
{
printf("%s?Register?Fail!",ErrBuf);
fflush(stdin);
getchar();
}
else
{
WriteDataToFile();
printf("\nRegister?Success!");
fflush(stdin);
getchar();
}
break;
case?3:
exit(0);
break;
default:
break;
}
}
return?0;
}
可以定義兩個字符數(shù)組;
一個存放正確密碼;
另一個數(shù)組內(nèi)的內(nèi)容由用戶輸入;
調(diào)用strcmp函數(shù),若返回值為0則說明兩者完全相等;
列子:
char a[10]="4488" //保存正確密碼
char b[10];
gets(b) //用戶輸入
if(strcmp(a,b)==0)
printf(" 匹配成功 ");
else
printf("匹配失敗");
更多追問追答
追問
#include
void main()
{
char a[10]="8844";
char b[10];
gets(b)
if(strcmp(a,b)==0)
printf("yes");
else
printf("no");
getch();
c語言中可采用getch()函數(shù)來實現(xiàn)輸入密碼字符時,不顯示字符到終端上,這時,只需要顯示出一個相應(yīng)的*就可以達(dá)到效果了。參考代碼及運行效果如下圖: