为什么能被译破

来源:百度知道 编辑:UC知道 时间:2024/06/29 01:23:48
如下程序
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void main()
{
char origPassword[8] = "123456";
char userPassword[8];
gets(userPassword); /* 读取用户输入的口令*/
if(strncmp(origPassword, userPassword, 8) != 0)
{
printf("Password doesn't match!\n");
exit(1);
}
printf("pass\n");
谁能说一下为什么输入形似asdfghjkasdfghjk重复两次8个字符的密码也能通过~~

if(strncmp(origPassword, userPassword, 8) != 0)

只是比较前8个字符

改为if(strcmp(origPassword, userPassword) != 0)

就过不了了

或者你也可以先对输入密码的位数进行处理

是非常奇怪,这都被你发现了,厉害!

我调试了一下,发现输入错误密码无法通过,但是用gets的时候小心输入的字符超过数组的大小。你输入的16个字符就已经超了。