當前位置:首頁 » 編程語言 » c語言設置一個密碼
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言設置一個密碼

發布時間: 2022-11-21 19:14:58

『壹』 【在線等…!!!】用c語言寫一個密碼程序

//---------------------------------------------------------------------------
#include
<stdio.h>
#include
<string.h>
#include
<ctype.h>
#define
PFE
"pas.dat"
/*保存密碼的文件*/
#define
DEFPAS
"123456"
/*初始密碼*/
void
setpass(void)
{
FILE
*fp=NULL;
char
pas[20];
printf("是否設置新密碼?(Y/N):");
fflush(stdin);
if
(tolower(getchar())=='y')
{
printf("請輸入新密碼:\
");
scanf("%20s",pas);
fp=fopen(PFE,"wb");
fwrite(pas,sizeof(char),strlen(pas),fp);
fclose(fp);
printf("已經設置新密碼,下次請使用新密碼登錄\
");
}
fflush(stdin);
}
int
main(void)
{
FILE
*pf;
char
pass[20]=DEFPAS,ch[20];
if
(pf=fopen(PFE,"rb"))
{
fread(pass,sizeof(char),20,pf);
fclose(pf);
}
printf("請輸入密碼:");
scanf("%s",ch);
if
(!strcmp(ch,pass))
{
printf("登錄成功\
");
setpass();
printf("歡迎使用本系統\
");
getchar();
}
else
printf("密碼錯誤,登錄失敗!\
");
return
0;
}
//---------------------------------------------------------------------------

『貳』 c語言 修改密碼初始密碼為123456,密碼包含數字和字母,數字必須大於2位

#include<stdio.h>
#include<string.h>
#include<ctype.h>
intmain()
{charpsw[21]="123456",t1[21],t2[21];
inti,n=0;
printf("請輸入初始密碼: ");
do
{gets(t1);
n++;
err=strcmp(t1,psw);
if(err)printf("初始密碼錯誤!請重新輸入! ");
}
while(err&&n<3);
if(strcmp(t1,psw))
{printf("密碼錯誤,不能登錄! ");
return0;
}
while(n<3)
{while(n<3)
{printf("請輸入新密碼: ");
gets(t1);
for(i=0;t1[i];i++)
if(isdigit(t1[i]))n++;
if(n<3)
{n=0;
printf("數字必須大於2位! ");
}
}
printf("請再次輸入新密碼: ");
gets(t2);
if(strcmp(t1,t2)==0)
printf("密碼修改成功! ");
else
{printf("二次密碼不一致! ");
n=0;
}
}
return0;
}

『叄』 用c語言編寫一個設置密碼的程序

#include "stdio.h"
int* set(void);
int* set(void)
{
int i;
static a[4];
printf("請輸入要設置的4位密碼 :");
for(i=0;i<4;i++)
{
scanf("%d",&a[i]);
}
return a;
}

int main()
{
int i,*a,b[4];
a=set();
printf("請輸入4位密碼 :");
for(i=0;i<4;i++)
{
scanf("%d",&b[i]);
}
i=0;
while(i<4)
{
if(a[i]==b[i])
{
printf("%d",a[i]);
i++;
}
else
{
break;
}
}
if(i==4)
{
printf("密碼正確\n");
}
else
{
printf("密碼錯誤\n");
}
return 0;

}

『肆』 懸賞100分 如何用c語言 寫一個密碼程序

clude "string.h"

//考慮到用資料庫文件保存注冊信息的話要使用access創建文件並且還要配置數據源,所以我的方法是採用將注冊信息保存到文件
//下面是完整的程序:

//登陸檢測函數
int login(char *name,char *password)
{
char info[10000];
char *p=info;
FILE *file=fopen("user","r");
int size;
if(file)
{
size=fread(info,1,10000,file);
while(size!=(int)p-(int)info)
{
if(!strcmp(p,name)&&!strcmp(p+strlen(p)+1,password))
{
fclose(file);
return 1;
}
p+=strlen(p)+1;
p+=strlen(p)+1;
}
}
fclose(file);
return 0;
}

//添加註冊信息入文件
void save(char *name,char *password)
{
FILE *file=fopen("user","a");
fwrite(name,1,strlen(name)+1,file);
fwrite(password,1,strlen(password)+1,file);
fclose(file);
}

#define PASSWORD "12345" //這里指定你要允許通過的密碼,比如12345,將引號里的數字改為你想要的即可
int main()
{
char password[100];
char name[100],c[100],password1[100];
tag1: printf("press 1 to register, or 2 to login\n");//輸入1為注冊,輸入2為登陸
while(1)
{
gets(c);
if('1'==c[0])
{
printf("please enter your name\n");//輸入姓名
gets(name);
tag2: printf("please enter your password\n");//輸入密碼
gets(password);
printf("please enter your password again\n");
gets(password1);
if(strcmp(password,password1))
{
//兩次密碼不一致,重輸
printf("the password you entered is different from the first one,please try again!\n");
goto tag2;
}
printf("register is completed!\n");//注冊成功
//下面實現將注冊信息加入文件保存
save(name,password);
goto tag1;
}
else if('2'==c[0])
{
tag3: printf("please enter your name:\n");
gets(name);
printf("please enter your password:\n");
gets(password);
if(login(name,password))//如果驗證通過,則
{
printf("login successfully!\n");

//這里添加成功登陸後要執行的代碼
}
else
{
printf("your name or password doesn't exist!\n");//否則重輸
goto tag3;
}

}
else
{
printf("invalid input!press 1 to register, or 2 to login\n");//輸入非法,重輸
goto tag1;
}

}

return 0;
}

餓,寫了我兩個小時啊,大哥,分一定要給我啊~~~~~~

『伍』 C語言問題,怎麼給系統設置一個密碼

void main(){
int menunum; //
char c;
int count=0;
do{
char inputs[10]; //
printf("輸入你的密碼: "); //
scanf("%s",inputs); //

if(strcmp(inputs,"password")==0) //自己設置密碼為password {
printf("\n\t\t\t 人口信息管理系統(可輸入漢字)\n");
printf(" |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|\n");
printf(" |1、輸入人口數據\t\t2、修改人口數據\t\t3、查找 |\n");
printf(" |4、排列人口數據\t\t5、列印人口信息\t\t6、刪除人口數據|\n");
printf(" |7、備份文件 \t\t8、恢復文件 \t\t9、清除已刪數據|\n");
printf(" |0、結束程序 \t\t\t\t\t |\n");
printf(" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
printf("\n 操作方式:");
scanf("%d",&menunum);
switch(menunum)
{
case 0:return;
case 1:{CreatPeople();break;}
case 2:{ChangePeople();break;}
case 3:{Find();break;}
case 4:{SortPeople();break;}
case 5:{PrintPeople();break;}
case 6:{DeletePeople();break;}
case 7:{BackPeople();break;}
case 8:{UpPeople();break;}
case 9:{ClearPeople();break;}
default: //switch中要加default的條件保證程序的健壯性
break;
}
printf("按回車鍵繼續\n");
c=getchar();c=getchar();
//system("cls");/*清屏*/
}
else //該保證三次輸入錯誤即程序結束
{
count++; //要初始化
if(count==3)
{
break;
return;
}
}
}while(1);
return;
}

『陸』 如何用C語言編寫密碼程序

1、用一個字元數組來存密碼
再用一個字元數組接收你的輸入,然後用strcmp
來比較,如果返回0則密碼是正確的
2、常式:

#include"stdio.h"
#include"string.h"
intmain()
{
charmima[100]="YuanShi888";
charinput[100]={0};
printf("請輸入密碼:");
gets(input);
if(strcmp(mima,input)==0)
printf("恭喜你,密碼正確! ");
else
printf("對不起,密碼輸入錯誤! ");

}

『柒』 C語言 密碼設置

WINDOWS操作系統:

//---------------------------------------------------------------------------

#include <stdio.h>
#include <conio.h>

int main(void)
{
char c;
while ((c=getch())!='q')
putchar('*');
return 0;
}
//---------------------------------------------------------------------------

LINUX操作系統:

//---------------------------------------------------------------------------

#include <curses.h>

int main(void)
{
initscr();

cbreak();
noecho();
while (getch()!='q') addch('*');
echo();
nocbreak;

endwin();
return 0;
}

/*編譯時要加上 -lcurses 參數*/
//---------------------------------------------------------------------------

『捌』 怎麼用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);

}

}