【在线等…!!!】用C语言写一个密码程序

Python013

【在线等…!!!】用C语言写一个密码程序,第1张

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

#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

}

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

#include "stdio.h"

int* set(void)

int* set(void)

{

int i

static a[4]

printf("请输入要设置的4位密码 :")

for(i=0i<4i++)

{

scanf("%d",&a[i])

}

return a

}

int main()

{

int i,*a,b[4]

a=set()

printf("请输入4位密码 :")

for(i=0i<4i++)

{

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

}

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

int main()

{

char password[10],password2[10]

memset(password,0,sizeof(password))

memset(password2,0,sizeof(password2))

printf("请设置8位数以内密码:\n\n")

scanf("%s",password)

printf("请设置校验密码:\n\n")

scanf("%s",password2)

if(atoi(password2)==atoi(password))

{

 printf("密码输入正确!:\n")

}

else

{

 printf("密码输入错误!:\n")

}

return 0

}