当前位置:首页 » 编程语言 » c语言验证用户密码
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言验证用户密码

发布时间: 2022-08-22 02:26:23

‘壹’ 用c语言:根据给定的算法,判断输入的密码是否正确

#include<stdio.h>
void main()
{
int n,password=123456,i=1;
while(1)
{
printf("输入密码:");
scanf("%d",&n);
if(n==password)
printf("Welcome to use the software\n");
else
{
if(i<3)
printf("剩余的可输入密码的次数为:%d\n",3-i);
else
printf("Password error ! You can not use the software\n");
i++;

}
if(i>=4||n==password)break;
}
}
这个是不需要用return的,简明一点,初学的应该会

‘贰’ C语言密码验证问题(程序设计求改)

1 b[8] 定义一个数组变量b,占用8个字节

你想要从键盘输入8个字符,通过gets函数接收数据。

但是,gets内部是这么干的:

不管你输入几个字符,都要在末尾补一个''

从键盘接收了8个字符放入数组b以后,b就被占满了,补的0就顺序放在了数组b的外边。恰好,数组b的外面就是数组a,补的0挤占了数组a的第一个字节。

然后无论怎么比较,这两个数组都是不等的,结果就是wrong

-----------

把数组b的空间定义的大一点,比如b[1000],要定义的足够大,让键盘怎么输入都占不满。

‘叁’ C语言用c写一个可以验证账号,密码和修改密码的程序

#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 <string.h>
char user[]="输入的帐号", pwd[]="输入的密码";
if (strcmp("真实帐号", user) == 0 && strcmp("对应密码", pwd) == 0) {
printf("验证成功!");
} else {
printf("帐号或密码错误!");
}

‘伍’ c语言 密码验证

用getch()非回显函数就可以了

#include <stdio.h>
#include <conio.h>
char mypw[10]="123";//预先设定的密码
int check(char a[])
{
int len=0;
while(len<10&&a[len]!=0x0d&&a[len]!='\0')
{
if(mypw[len]!=a[len]) return 0;
len++;
}
return 1;
}

int main()
{
char pw[10];//用户输入的密码
int i;
for(i=0;i<10;i++) pw[i]='\0';
int len=0;
printf("输入密码\n");
while(len<10&&0x0d!=(pw[len]=getch()))//用getch()非回显函数
{
len++;
printf("*");
}
printf("\n");
if(check(pw)) printf("密码正确");
else printf("密码错误");
getchar();
return 0;
}

‘陆’ C语言编写一个密码验证程序。

#include<stdio.h>
#include<conio.h>
voidmain()
{
charexp1='1',exp2='2',exp3='3';//预期值
charch1,ch2,ch3;
ch1=getch();
printf("*");

ch2=getch();
printf("*");

ch3=getch();
printf("* ");
if(ch1==exp1&&ch2==exp2&&ch3==exp3)
{
printf("欢迎进入系统 ");
}
else
{
printf("密码输入错误,请退出 ");
}
}

‘柒’ C语言的密码检测怎么做

conio.h不是c标准头文件,建议不要用这个头文件。把这个头文件删掉。

将读入密码那行的函数改用gets

gets(input_pass);

另外为了避免bug,input_pass最好弄大一点。

‘捌’ C语言中密码校验怎么做

给你个参考:

#include<stdio.h>
#include<conio.h> //用getch()函数时要的文件头
#include<string.h>

#define USER "admin"
#define PWD "admin"

void main()
{
char user[20], pwd[16], ch;
int count=0, i=0;
while(count<3) //3次机会输入正确密码
{
printf("user name:");
gets(user);
printf("password:");
while((ch=getch())!=13&&i<16) //将输入的密码转换成字符****
{
putchar('*');
pwd[i]=ch;
i++;
}
pwd[i]=0;
if(!strcmp(USER,user)&&!strcmp(PWD,pwd))
break;
else
printf("\nincorrect user name or password!\n");
count++;
}
printf("\nlogin successful!\n");
}

‘玖’ c语言编程 用户登录验证密码

//核心代码如下

//定义计数变量
intcount=0;

if(登录失败)
{
count++;
if(count>=3)
{
printf("不给进入");
//视情况而定是否需要重置count的值
count=0;
}
}

‘拾’ 用C语言编写一个密码验证程序

#include <stdio.h>
#include <string.h>

typedef struct
{
long number; //用户编号 6位
char name[20]; //用户名
char password[8]; //用户密码
int power; //权限判断 1 为管理员2为普通用户
} user;
user yh[100]={100000,"gavin","gavine",1,100001,"wnag","wangf",2};
int length = 2;

int checkuser(long num, const char *nm, const char *pwd)
{
int i;
for (i = 0; i < length; ++i)
{
if (yh[i].number == num && !strcmp(yh[i].name, nm) && !strcmp(yh[i].password, pwd))
{
if (1==yh[i].power)
return 1;
else
return 2;
}
}
}

void main()
{
printf("%d\n", checkuser(100000, "gavin", "gavine"));
}