‘壹’ 【在线等…!!!】用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);
}
}