#include "StdAfx.h" #include "SoftAuther.h" SINGLETON_IMPLEMENT(SoftAuther) SoftAuther::SoftAuther(void) : CpuCodeAuth(""),m_Date(0),m_AgentCount(0),m_IvrFlowCount(0) { keyValue['0']='S'; keyValue['1']='D'; keyValue['2']='1'; keyValue['3']='7'; keyValue['4']='6'; keyValue['5']='F'; keyValue['6']='G'; keyValue['7']='C'; keyValue['8']='P'; keyValue['9']='A'; keyValue['A']='2'; keyValue['B']='8'; keyValue['C']='H'; keyValue['D']='O'; keyValue['E']='K'; keyValue['F']='I'; keyValue['G']='U'; keyValue['H']='J'; keyValue['I']='Y'; keyValue['J']='L'; keyValue['K']='T'; keyValue['L']='Z'; keyValue['M']='9'; keyValue['N']='R'; keyValue['O']='5'; keyValue['P']='0'; keyValue['Q']='4'; keyValue['R']='E'; keyValue['S']='M'; keyValue['T']='X'; keyValue['U']='W'; keyValue['V']='V'; keyValue['W']='N'; keyValue['X']='B'; keyValue['Y']='3'; keyValue['Z']='Q'; keyValue2['0']='4'; keyValue2['1']='6'; keyValue2['2']='O'; keyValue2['3']='L'; keyValue2['4']='5'; keyValue2['5']='P'; keyValue2['6']='M'; keyValue2['7']='N'; keyValue2['8']='3'; keyValue2['9']='K'; keyValue2['A']='7'; keyValue2['B']='I'; keyValue2['C']='2'; keyValue2['D']='U'; keyValue2['E']='Y'; keyValue2['F']='H'; keyValue2['G']='N'; keyValue2['H']='B'; keyValue2['I']='1'; keyValue2['J']='8'; keyValue2['K']='G'; keyValue2['L']='T'; keyValue2['M']='0'; keyValue2['N']='F'; keyValue2['O']='V'; keyValue2['P']='C'; keyValue2['Q']='9'; keyValue2['R']='D'; keyValue2['S']='R'; keyValue2['T']='E'; keyValue2['U']='W'; keyValue2['V']='S'; keyValue2['W']='X'; keyValue2['X']='Z'; keyValue2['Y']='A'; keyValue2['Z']='Q'; keyValue3['0']='N'; keyValue3['1']='P'; keyValue3['2']='R'; keyValue3['3']='V'; keyValue3['4']='I'; keyValue3['5']='T'; keyValue3['6']='A'; keyValue3['7']='C'; keyValue3['8']='Z'; keyValue3['9']='G'; keyValue3['N']='0'; keyValue3['P']='1'; keyValue3['R']='2'; keyValue3['V']='3'; keyValue3['I']='4'; keyValue3['T']='5'; keyValue3['A']='6'; keyValue3['C']='7'; keyValue3['Z']='8'; keyValue3['G']='9'; } SoftAuther::~SoftAuther(void) { } void SoftAuther::WritessFile(char* fileName,char ch[50]) { FILE* pfile; pfile=fopen(fileName,"w"); fprintf(pfile,ch); fclose(pfile); } void SoftAuther::ReadssFile(char* fileName,char ch[50]) { FILE* pfile; pfile=fopen(fileName,"r"); if(pfile==NULL) return; fscanf(pfile,"%s",ch); fclose(pfile); } char outch[50]={0}; char* SoftAuther::GetKeyByNumber(string CpuNumber) { memset(outch,0,50); for(int i=0;i::iterator it_find; it_find= keyValue2.find(c); return it_find->second; } char SoftAuther::GetCharByChar(char c) { map::iterator it_find; it_find= keyValue.find(c); return it_find->second; } char vendor_serialnumber[0x14] = { 0 }; char* SoftAuther::GetCpuID() { std::array cpui; //#include __cpuid(cpui.data(), 0x0); //cpui[0] = "funcition_id的最大值" int nIds_ = cpui[0]; std::vector> data_; //保存遍历到的所有cpui的值 for (int i=0;i<=nIds_;++i) { __cpuidex(cpui.data(), i, 0); data_.push_back(cpui); } //reinterpret_cast(vendor) //*reinterpret_cast(vendor) //索引0 0+4 0+8的值构成了CPU芯片的名称 char vendor[0x20] = { 0 }; *reinterpret_cast(vendor) = data_[0][1]; *reinterpret_cast(vendor + 4) = data_[0][3]; *reinterpret_cast(vendor + 8) = data_[0][2]; // vendor="GenuineIntel" std::string vendor_ = vendor; sprintf_s(vendor_serialnumber, sizeof(vendor_serialnumber), "%08X", data_[1][0]); return vendor_serialnumber; } bool SoftAuther::ComareData(char* id,char* psw) { char* getPas=GetKeyByNumber(id); char chcpu[50]={0}; if(strlen(psw)!=28) return false; memcpy(chcpu,psw,16); char chdate[50]={0}; CString Allpsd=psw; CString CodeDate = Allpsd.Mid(16,6); int idate = TransCodeToDate(CodeDate.GetBuffer(0)); //sysTIme; CTime time = CTime::GetCurrentTime(); ///构造CTime对象 int m_nYear = time.GetYear(); ///年 m_nYear=m_nYear-2000; int m_nMonth = time.GetMonth(); ///月 int m_nDay = time.GetDay(); ///日 int SysTime=m_nYear*10000+m_nMonth*100+m_nDay; if(0==strcmp(getPas,chcpu)) { if (SysTime<=idate) { return true; } return false; } else { return false; } } int SoftAuther::TransCodeToDate(string code) { if(code.length()<=0) return 0; char chDate[50]="0"; for(int i=0;i::iterator it_find; it_find= keyValue3.find(c); return it_find->second; } bool SoftAuther::CompareDate(int current,int readdate) { if(current<=readdate) { return false; } else { return true; } } void SoftAuther::ReadssDateFile(char* fileName,char ch[50]) { char chhh[50]; FILE* pfile; pfile=fopen(fileName,"r"); if(pfile==NULL) return; fscanf(pfile,"%s",chhh); CString strAll=ch; CString strDate = strAll.Mid(16,22); memcpy(ch,strDate,strDate.GetLength()); fclose(pfile); } void SoftAuther::InitAutherData(char* FileName) { char chhh[50]={0}; FILE* pfile; pfile=fopen(FileName,"r"); if(pfile==NULL) return; fscanf(pfile,"%s",chhh); CString m_strAutherCode = chhh; fclose(pfile); CpuCodeAuth = m_strAutherCode.Mid(0,16); CString DateCode = m_strAutherCode.Mid(16,6); CString AgentCode = m_strAutherCode.Mid(22,3); CString IvrFlowCode =m_strAutherCode.Mid(25,3); m_Date = TransCodeToDate(DateCode.GetBuffer(0)); m_AgentCount = TransCodeToDate(AgentCode.GetBuffer(0)); m_IvrFlowCount = TransCodeToDate(IvrFlowCode.GetBuffer(0)); }