• 大小: 4KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-13
  • 语言: C/C++
  • 标签: c++  TOTP  

资源简介

实现一次性口令(OTP,One Time Password)身份认证程序

资源截图

代码片段和文件信息

#include “md5.h“
#include
#include
#include
#include
#include
using namespace std;

struct inf  //系统用户存储信息结构
{
char uid[50]; //用户名
int r;  //挑战值
char answer[50]; //应答值
char password[50]; //密码
};

inf infor[300];
int n=0;

void init()
{
char uid[50]answer[50]password[50];
    int r;
fstream file; 
file.open(“lib.txt“ios::in);
if(!file);
else
{
while(file>>uid>>r>>answer>>password)
{
strcpy(infor[n].uiduid);
infor[n].r=r;
strcpy(infor[n].answeranswer);
strcpy(infor[n].passwordpassword);
n++;
}
}
file.close();
}

void reg()
{
char uid[50]password1[50]password2[50]ans[100]={0}answer[50];
int ri;
while(1)
{
cout<<“请输入用户名: “;
cin>>uid;
for(i=0;i if(strcmp(infor[i].uiduid)==0)
{
cout< break;
}
if(i==n) break;
}
while(1)
{
cout<<“请输入密码: “;
cin>>password1;
cout<<“请再次输入密码: “;
cin>>password2;
if(strcmp(password1password2)==0)
break;
else
{
cout< }
}
srand(time(0));
r=rand();
infor[n].r=r;
i=0;
    while(r!=0)
{
ans[i]=r%10+‘0‘;
r/=10;
i++;
}
strcat(anspassword1);
    strcpy(answerMD5String(ans));

strcpy(infor[n].uiduid);
strcpy(infor[n].answeranswer);
strcpy(infor[n].passwordpassword1);
n++;

cout< system(“pause“);
system(“cls“);
}

void check()
{
char uid[50]answer[50]ans[100]={0};
int rij;
char ch;
cout<<“请输入用户名: “;
cin>>uid;
for(i=0;i {
if(strcmp(infor[i].uiduid)==0)
{
cout<<“挑战值为: “< cout<<“是否返回进行应答值计算(y/n): “;
cin>>ch;
if(ch==‘y‘) cout< else if(ch==‘n‘)
{
cout<<“请输入应答值: “;
cin>>answer;
if(strcmp(answerinfor[i].answer)==0)
{
cout< srand(time(0));
r=rand();
infor[i].r=r;
j=0;
while(r!=0)
{
ans[j]=r%10+‘0‘;
r/=10;
j++;
}
strcat(ansinfor[i].password);
strcpy(infor[i].answerMD5String(ans));
}
else
cout< }
else cout< break;
}
}
if(i==n)
cout< system(“pause“);
system(“cls“);
}

void compute()
{

char password[50]answer[50]ans[100]={0};
int ri;

cout<<“请输入挑战值: “;
cin>>r;
cout<<“请输入密码: “;
cin>>password;

i=0;
    while(r!=0)
{
ans[i]=r%10+‘0‘;
r/=10;
i++;
}
strcat(anspassword);
    strcpy(answerMD5String(ans));
cout<
system(“pause“);
system(“cls“);

}

int main()
{
char ch; 
int i;
init();
while(1)
{
cout< cout<<“                             1.用户注册“< <<“                             2.身份认证“< <<“                         

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-10-29 15:04  otp\
     文件        8208  2009-06-25 22:10  otp\md5.h
     文件        3695  2009-06-26 14:39  otp\otp.cpp

评论

共有 条评论