當前位置:首頁 » 編程語言 » 檢查密碼的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;

}