该项目如下:

传统的密码输入方案容易受到“肩膀冲浪”的攻击,在这种情况下,攻击者会看到毫无戒心的用户输入他们的密码或PIN码,并在以后使用它来访问该帐户 . 解决这个问题的一种方法是使用随机挑战 - 响应系统 . 在这些系统中,用户响应于随机生成的挑战,每次基于秘密输入不同的信息 . 请考虑以下方案,其中密码由五位数的PIN号码(00000至99999)组成 . 为每个数字分配一个1,2或3的随机数 . 用户输入与其PIN相对应的随机数,而不是实际的PIN号 . 例如,考虑实际的PIN号为12345.要进行身份验证,用户将看到如下屏幕:PIN:0 1 2 3 4 5 6 7 8 9
NUM:3 2 3 1 1 3 2 2 1 3
用户将输入23113而不是12345.即使攻击者截获该条目,也不会泄露密码,因为23113可能对应于其他PIN号码,例如69440或70439.下次用户登录时,不同的序列将生成随机数,例如:PIN:0 1 2 3 4 5 6 7 8 9
NUM:1 1 2 3 1 2 2 3 3 3
您的程序应该模拟身份验证过程 . 在程序中存储实际的PIN码 . 程序应使用数组为0到9之间的数字分配随机数 . 将随机数输出到屏幕,输入用户的响应,并输出用户的响应是否与PIN号正确匹配 .

我的代码中的一个循环不能正常工作,因为当用户输入错误的PIN号时,程序将完成,但不会要求用户再次尝试 . 我还需要帮助添加以下两个:向量,指针或类,但我不知道如何 .

#include <iostream>
#include <string>
#include <ctime> // for srand function
#include <cstdlib>
using namespace std;
void generateRandomNumbers(int *random){ // Uses current time as for the random generator
srand(time(0));

for(int i=0;i<10;i++){
random[i] = 1 + rand() % 3;
}
}
 bool isMatch(string pin,string randomPin,int *random){
int index;
for(int i=0;i<(int)pin.length();i++){ //converting pin number to int so that we can check the random number at that index
index = pin[i]-'0';
if((randomPin[i]-'0') != random[index-1])
return false;
}
return true;
}
int main()
{
string pin = "12345";
string randomPin;
int random[10];
generateRandomNumbers(random);
cout << "Randomly generated numbers " << endl;
for(int i=0;i<10;i++) //loop to print random generated numbers 
{
cout << random[i] << " ";
}
cout << endl;
cout << "Now please enter your pin in terms of random numbers: "; //prompt and read the user's password
cin >> randomPin;
if(isMatch(pin,randomPin,random)){
cout << "Correct. Both matches" << endl;
}
else
{
cout << "Sorry you have entered the wrong pin.." << endl;
}
}