#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;
}
㈡ 如何使用c语言编写一个密码程序
密码保存在文件中,从文件中读取密码,但是没做容错和异常处理,仅供参考
#include <stdio.h>
#include <string.h>
#define PSDLEN 6
void inputPsd(char *str) /*处理输入*/
{
int i;
for(i = 0; i < PSDLEN; i++)
{
while(1)
{
str[i] = getch();
if(str[i] == '\b') /*处理退格键*/
{
i--;
if(i < 0)
{
i = 0;
}
else
{
printf("\b \b");
}
continue;
}
else if(str[i] == '\r') /*处理回车键*/
{
continue;
}
else
{
printf("*");
break;
}
}
}
str[i] = '\0';
printf("\n");
}
int checkFirst() /*检测是否是第一次使用*/
{
FILE *fp;
if((fp = fopen("psd.dat", "rb")) == NULL)
{
return 1;
}
fclose(fp);
return 0;
}
void firstUse() /*第一次使用 需要输入密码*/
{
FILE *fp;
int i;
char passwd[PSDLEN + 1];
char checkPsd[PSDLEN + 1];
if((fp = fopen("psd.dat", "wb")) == NULL)
{
printf("Creat password error!\n");
exit(1);
}
while(1)
{
printf("Please input password:");
inputPsd(passwd);
printf("\nPlease input password again:");
inputPsd(checkPsd);
if(!strcmp(passwd, checkPsd))
{
break;
}
printf("\ncheck password error! \n");
}
fwrite(passwd, sizeof(char), PSDLEN, fp);
fclose(fp);
}
void login() /*核对密码,并登录*/
{
FILE *fp;
int i, num = 3;
char passwd[PSDLEN + 1];
char checkPsd[PSDLEN + 1];
if((fp = fopen("psd.dat", "rb")) == NULL)
{
puts("Open psd.dat error");
exit(1);
}
fread(passwd, sizeof(char), PSDLEN, fp);
fclose(fp);
passwd[PSDLEN] = '\0';
printf("Please input password to login");
while(num)
{
printf("you have %d chances to cry:\n", num);
inputPsd(checkPsd);
if(!strcmp(passwd, checkPsd))
{
break;
}
puts("\npassword error,Please input again");
num--;
}
if(!num)
{
puts("Press any key to exit...");
getch();
exit(0);
}
else
{
puts("\n--------\nWelcome!\n--------\n");
}
}
void main()
{
if(checkFirst())
{
firstUse();
}
else
login();
getch();
}
㈢ 如何编译一个C语言密码程序,判断密码的位数(如5位),如果输入的密码小于5位或者大于五位都有相应提示
代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
intmain()
{
intlen=0;
charpassword[10]={0};
printf("请输入密码:");
scanf("%s",password);
len=strlen(password);
if(len<5){
printf("密码长度不足! "扮顷);
}
elseif(len>5){
printf("密码长度过长! ");
}
else{
//默认密码是银轮admin
if(strcmp(password,"admin")==0){
printf("登录成功! ");
}
else{
printf("密码不锋缺信正确! ");
}
}
system("pause");
return0;
}
㈣ 如何用c语言编写英文密码还要判断正不正确的那种
#include <stdio.h>
#include <string.h>
int main()
{
char a[100],*b="miku";
改猜 gets(a);
if(strncmp(a,b,strlen(b))==0)
puts("yes");
核毕型 else
数者 puts("no");
return 0;
}
㈤ 请教高手如何用C语言译密码
读出每个字符,然后给它加上4就可以了,如果要还原,就用每个字符减去4.
㈥ 悬赏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语言编译一有关于密码的程序。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<windows.h>
typedefstruct
{
intx;
inty;
}PT_STRUCT;
typedefstruct
{
charuser[20];
charpw[20];
}USER_STRUCT;
PT_STRUCTpt;
boolLoginSuccess=false;
charCurrentUser[20]={'