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

检查密码的c语言

发布时间: 2022-12-17 22:23:47

A. c语言编写判断输入密码是否正确...

其实啊,密码一般是字符串型的....建议选择字符串。int a;
scanf("%d",&a);
long a;scanf("%ld",&a);

B. 关于c语言中判断一个密码正确的问题

可以使用库函数strcmp判断,具体如下:

strcmp是C语言比较字符串的库函数,形式为int strcmp(char *a, char *b);

该函数会对a和b的每个字符,按照ascii码值比较,如果二者完全相同返回0;如果a的ascii码值先出现较大者,会返回1;否则返回-1。

C. 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");
}

D. 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;
}

E. c语言实现输入一个密码 并判断密码是否正确还是大于或小于密码

intpassword;
scanf("%d ",&password);
if(password==123456){
printf("密码正确");
}else{
if(password<=123456){
printf("小于密码");
}else{
printf("大于密码");
}

F. c语言编写判断输入密码是否正确...

注意变量类型,INT是整数型,范围是(-255 ,255)的整数, 你可以改用字符串变量

G. 用C语言写简单密码检测程序

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define pi 3.1415926
float area(float s);
void main()
{
char srmima[16],mima[16]="sunshibin1020";
int i=0,j;
float r,s;
while(1)
{
for(j=0;j<30;j++)
printf("-");
printf("\n");
printf("请输入密码:");
gets(srmima);
for(j=0;j<30;j++)
printf("-");
printf("\n");
if(strcmp(srmima,mima)==0)
{
printf("恭喜你,密码正确!\n");
break;
}
i++;
if(i>2)
{
printf("很遗憾,密码输入错误!\n");
exit(0);
}
}
area(r);
printf("圆面积为:%f",s);
getchar();
}
float area(float r)
{
float s;
while(1)
{
printf("\n请输入半径: r:");
scanf("%f",&r);
if (r<0)
break;
s=pi*r*r;
printf("s=%.2f\n",s);
}
exit(0);
}

H. c语言设计密码检测程序

#include <stdio.h>

#define UC (1U<<1) // upper case
#define LC (1U<<2) // lower case
#define NUM (1U<<3) // 0-9

#define ALL (UC|LC|NUM)

int check(const char pass1[], const char pass2[])
{
const char *p = &pass1[0];
unsigned int flag = 0;

if (strlen(pass1) < 6 || strlen(pass1) > 8)
{
printf("password length is 6 to 8.\n");
return 1;
}

if (strcmp(pass1, pass2))
{
printf("the tow passwords are diffrence.\n");
return 2;
}

while (*p)
{
if (*p >= 'a' && *p <= 'z') flag |= LC;
else if (*p >= 'A' && *p <= 'Z') flag |= UC;
else if (*p >= '0' && *p <= '9') flag |= NUM;
else
{
printf("in valid charactor: %c.\n", *p);
return 3;
}
++p;
}

if (flag == ALL) return 0;

if ((flag & UC) == 0)
{
printf("lack of uppercase.\n");
}

if ((flag & LC) == 0)
{
printf("lack of lowercase.\n");
}

if ((flag & NUM) == 0)
{
printf("lack of number.\n");
}
return -1;
}

int main(int argc, char *argv[])
{
char pass1[100];
char pass2[100];

do {
printf("input password:");
scanf("%s", pass1);
printf("repeat password:");
scanf("%s", pass2);
} while (check(pass1, pass2) != 0);

return 0;
}

I. C语言检查密码有效性

C语言代码和运行结果如下:

输出符合要求,望采纳~

附源码:

#include <stdio.h>

#include <ctype.h>

int main() {

int i, upper, lower, digit, punct;

char s[13]; // 保存输入的密码

while (1) {

printf("请输入密码(含大写、小写、数字和标点字符): ");

scanf("%s", s);

i = upper = lower = digit = punct = 0;

while (s[i] != '') {

if (isupper(s[i]) > 0) upper++;

else if (islower(s[i]) > 0) lower++;

else if (isdigit(s[i]) > 0) digit++;

else if (ispunct(s[i]) > 0) punct++;

i++;

}

if (upper == 0 || lower == 0 || digit == 0 || punct == 0)

printf("密码不合规,请重新设置 ");

else {

printf("设置密码成功! ");

break;

}

}

return 0;

}