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

c语言密码长度

发布时间: 2023-04-15 06:45:14

⑴ 用c语言生成八位的随机密码

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
char pool[]=
{
Ɔ',Ƈ',ƈ',Ɖ',Ɗ',Ƌ',ƌ',ƍ',Ǝ',Ə',
'a','b','c','d','e','f','g','h','i','j',
'k','l','m','n','o','p','q','r','s','t',
'u','v','w','x','y','z','A','B','C','D',
'E','F','G','H','I','J','K','L','M','N',
'O','P','Q','R','S','T','U','V','W','X',
'Y','Z'
};//随机池
srand(time(0));
char pwd[9];
pwd[8]=''//方便作为字符串输出处理
int i=0;
while(i!=8)
{
pwd[i++]=pool[rand()%sizeof(pool)];
}
printf("密码%s",pwd);

}

⑵ 如何编译一个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>

#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;
}

⑷ C语言如何实现输入密码以星号显示

呵呵!
这个很简单的啊,你只要将你的密码保存在一个数组中啊,以便下次匹配密码时使用啊,但你的输出为“*”就好啦,给你个例子啊
密码长度为6哈
#include <stdio.h>
int main()
{

int c[6];
int i = 0;
while(i < 6)
{
c[i++] = getchar();
putchar('*');
}
return 0;
}