C语言用字符串比较函数验证账号和密码?

C语言用字符串比较函数验证账号和密码?,第1张

#include <string.h>

char user[]="输入的帐号", pwd[]="输入的密码"

if (strcmp("真实帐号", user) == 0 &&strcmp("对应密码", pwd) == 0) {

printf("验证成功!")

} else {

printf("帐号或密码错误!")

}

#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

}

#include<stdio.h>

#include<conio.h>

void main()

{

 char exp1 = '1', exp2 = '2', exp3 = '3'//预期值

 char ch1, ch2, ch3

 ch1 = getch()

 printf("*")

 

 ch2 = getch()

 printf("*")

 

 ch3 = getch()

 printf("*\n")

 if(ch1 == exp1 && ch2 == exp2 && ch3 == exp3)

 {

  printf("欢迎进入系统\n")

 }

 else

 {

  printf("密码输入错误,请退出\n")

 }

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11443997.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存