Ⅰ 用c語言程序編寫用戶名密碼 程序
#include<stdio.h>
#include<string.h>
void main()
{
int i,flag1,flag2;
char name[20]="lushan",password[10]="123456";
char person[20],password1[10];
for(i=0;i!=3;)
{
printf("Please input the name:\n");
gets(person);
flag1=strcmp(person,name);
printf("Please input the password:\n");
gets(password1);
flag2=strcmp(password,password1);
if(flag1==0&&flag2==0)
{
printf("Pass successfully!");
break;
}
else
{
printf("You have enter the wrong name or password!\n");
i++;
}
}
}
Ⅱ C語言編寫用戶登錄程序
艾達的小刀
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
/*隨機碼產生函數*/
void RandomCode (char Rcode[])
{
int i;
srand ((unsigned int)time(NULL));
for (i = 0; i < 3; ++i)
Rcode[i] = rand()%10 + '0';
Rcode[i] = '\0';
}
/*登陸函數,判斷信息是否匹配,若匹配返回1,否則返回0*/
int LandedApp (char *password[], char Rcode[])
{
char name[10] = {0};
char pword[10] = {0};
char rcode[4] = {0};
printf ("用戶名 : ");
gets (name);
printf ("密碼 : ");
gets (pword);
printf ("隨機碼 : ");
gets (rcode);
if (strcmp (name, password[0]) != 0 || strcmp (pword, password[1]) != 0 || strcmp (rcode, Rcode) != 0)
return 0;
else
return 1;
}
int main ()
{
char * password[2] = {"admin", "admin123"}; //用戶名和密碼
char rc[4] = {0}; //隨機碼
int count = 3; //可輸入次數
puts ("請輸入用戶名,密碼和隨機碼:");
while (count)
{
RandomCode (rc);
printf ("隨機碼 : %s\n", rc);
if (LandedApp(password, rc) != 0)
break;
--count;
if (count != 0)
puts ("錯誤的用戶名或密碼或隨機碼,請重新輸入: ");
}
if (count != 0)
puts ("\n成功登陸!");
else
puts ("\n登錄失敗 !");
return 0;
}
艾達的小刀
Ⅲ c語言編寫程序,模擬用戶注冊和登錄的過程,實現用戶的注冊和登錄
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char username[20];
char password[20];
char s1[20],s2[20];
int n=0;
printf("--------------------\n 1 注冊 \n 2 登錄 \n 0 退出 \n--------------------\n 請選擇(0-2)\n");
scanf("%d",&n);
while(n==1){
char usernametmp[20];//tmp作為臨時保存單位
char passwordtmp[20];
printf("請輸入用戶名:");
scanf("%s",usernametmp);
strcpy(username,usernametmp);
printf("請輸入密碼:");
scanf("%s",passwordtmp);
strcpy(password,passwordtmp);
printf("注冊成功!\n");
break;
}
while(n==2)
{
printf("輸入用戶名:");
fflush(stdin);//清空輸入緩沖區
gets(s1);
printf("輸入密碼:");
fflush(stdin);
gets(s2);
if((strcmp(s1,username)==0)&&(strcmp(s2,password)==0)){
printf("登陸成功\n");}
else{
printf("用戶名或密碼錯誤!登錄失敗!\n");}
}
return 0;
}
Ⅳ c語言編寫用戶登錄程序
代碼如下:
#include<stdio.h>
#pragma warning(disable:4996)
#include<string.h>
int main()
{
int i = 0;
char password[10] = { 0 };
printf("請輸入密碼:");
while (i < 3)
{
scanf("%s", password);
printf(" ");
if (strcmp(password, "972816") == 0)
{
printf("登錄成功 ");
break;
}
else
{
i++;
if (i != 3)
printf("再輸入一次");
}
}
if (i == 3)
printf("密碼錯誤三次退出登錄界面 ");
system("pause");
return 0;
(4)c語言編寫用戶名擴展閱讀:
#include後面有兩種方式,<>;和""前者先在標准庫中查找,查找不到在path中查找。後者為文件路徑,若直接是文件名則在項目根目錄下查找。
引用方法:#include<stdio.h>
注意事項:在TC2.0中,允許不引用此頭文件而直接調用其中的函數,但這種做法是不標準的。也不建議這樣做。以避免出現在其他IDE中無法編譯或執行的問題。
Ⅳ C語言編寫程序,用戶名為:used,密碼為123
#include<stdio.h>
void main()
{int a;
printf("用戶名:used\n請輸入密碼\n");
scanf("%3d",&a);
if (a==123) printf("歡迎使用\n");
else printf("你輸入錯誤\n");
}
Ⅵ C語言編寫一個用戶登陸的程序
代碼如下:
#include<stdio.h>
#pragma warning(disable:4996)
#include<string.h>
int main()
{
int i = 0;
char password[10] = { 0 };
printf("請輸入密碼:");
while (i < 3)
{
scanf("%s", password);
printf(" ");
if (strcmp(password, "972816") == 0)
{
printf("登錄成功 ");
break;
}
else
{
i++;
if (i != 3)
printf("再輸入一次");
}
}
if (i == 3)
printf("密碼錯誤三次退出登錄界面 ");
system("pause");
return 0;
(6)c語言編寫用戶名擴展閱讀:
#include後面有兩種方式,<>;和""前者先在標准庫中查找,查找不到在path中查找。後者為文件路徑,若直接是文件名則在項目根目錄下查找。
引用方法:#include<stdio.h>
注意事項:在TC2.0中,允許不引用此頭文件而直接調用其中的函數,但這種做法是不標準的。也不建議這樣做。以避免出現在其他IDE中無法編譯或執行的問題。
Ⅶ 怎麼用c語言寫一個創建用戶名和密碼並且能修改密碼的程序
#include <stdio.h>//我自己做的,你拿去用吧!
#include <string.h>
struct e
{
char a[10];
char b[10];
}z;
int main()
{ int t=0;
char s[10],d[10];
FILE *p;
void as();
if ((p=fopen("m.txt","r+"))==NULL)
{
p=fopen("m.txt","w+");
t=1;
}
if(t==1)
{
printf("當前沒有任何用戶\n");
printf("請新建用戶名: ");
scanf("%s",s);
printf("為用戶設置密碼: ");
scanf("%s",d);
strcpy(z.a,s);
strcpy(z.b,d);
fprintf(p,"%s %s",z.a,z.b);
fclose(p);
}
if(t==0)
{
printf("請輸入用戶名: ");
scanf("%s",s);
fscanf(p,"%s %s",z.a,z.b);
fclose(p);
if (!strcmp(z.a,s))
{
printf("請輸入密碼:");
scanf("%s",d);getchar();
if(!strcmp(z.b,d))
{ char i;
printf("是否要修改密碼?(輸入y修改,n退出!)");
scanf("%c",&i);
if(i=='y')
{
printf("請輸入修改密碼:");
scanf("%s",z.b);
p=fopen("m.txt","w+");
fprintf(p,"%s %s",z.a,z.b);
fclose(p);
printf("修改成功!");
}
}
else printf("密碼錯誤!");
}
else printf("用戶名錯誤");
fclose(p);
}
}
Ⅷ 怎麼用c語言寫一個創建用戶名和密碼並且能
#include
//我自己做的,你拿去用吧!
#include
struct
e
{
char
a[10];
char
b[10];
}z;
int
main()
{
int
t=0;
char
s[10],d[10];
FILE
*p;
void
as();
if
((p=fopen("m.txt","r+"))==NULL)
{
p=fopen("m.txt","w+");
t=1;
}
if(t==1)
{
printf("當前沒有任何用戶\n");
printf("請新建用戶名:
");
scanf("%s",s);
printf("為用戶設置密碼:
");
scanf("%s",d);
strcpy(z.a,s);
strcpy(z.b,d);
fprintf(p,"%s
%s",z.a,z.b);
fclose(p);
}
if(t==0)
{
printf("請輸入用戶名:
");
scanf("%s",s);
fscanf(p,"%s
%s",z.a,z.b);
fclose(p);
if
(!strcmp(z.a,s))
{
printf("請輸入密碼:");
scanf("%s",d);getchar();
if(!strcmp(z.b,d))
{
char
i;
printf("是否要修改密碼?(輸入y修改,n退出!)");
scanf("%c",&i);
if(i=='y')
{
printf("請輸入修改密碼:");
scanf("%s",z.b);
p=fopen("m.txt","w+");
fprintf(p,"%s
%s",z.a,z.b);
fclose(p);
printf("修改成功!");
}
}
else
printf("密碼錯誤!");
}
else
printf("用戶名錯誤");
fclose(p);
}
}
Ⅸ 如何用C語言編程實現用戶登錄
C語言的話,一般用戶信息存儲在結構體鏈表裡
你輸入用戶名回車以後,需要遍歷鏈表,使用strcmp()函數逐一對比鏈表裡是否存儲了你輸入的用戶名。不存在輸出「無此用戶」,存在繼續輸入密碼,將密碼與此結點的密碼信息對比,處理方式同用戶名;
至少三次輸入錯誤,可設一個整形變數index = 0,每錯誤一次執行index++,當if(index==3)成立時,輸出相應信息,並執行exit(1);
Ⅹ 在c語言中如何實現1、 編程實現用戶登錄問題,如果用戶名和密碼都輸入正確,則提示「歡迎登陸!」,假定用
#include<stdio.h>
void main()
{
char name;
int code;
bool b=true;
while(b)
{
printf("\n請輸入用戶名:");
scanf("%s",&name);
printf("\n請輸入密碼:");
scanf("%d",&code);
if(name=='h'&&code==0)
{
printf("歡迎光臨\n");
b=false;
}
else{
printf("重新登錄\n");
}
}
}
希望對你有所幫助,不明白hi我。。