hd

SoftAuther.cpp 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. #include "StdAfx.h"
  2. #include "SoftAuther.h"
  3. SINGLETON_IMPLEMENT(SoftAuther)
  4. SoftAuther::SoftAuther(void) : CpuCodeAuth(""),m_Date(0),m_AgentCount(0),m_IvrFlowCount(0)
  5. {
  6. keyValue['0']='S';
  7. keyValue['1']='D';
  8. keyValue['2']='1';
  9. keyValue['3']='7';
  10. keyValue['4']='6';
  11. keyValue['5']='F';
  12. keyValue['6']='G';
  13. keyValue['7']='C';
  14. keyValue['8']='P';
  15. keyValue['9']='A';
  16. keyValue['A']='2';
  17. keyValue['B']='8';
  18. keyValue['C']='H';
  19. keyValue['D']='O';
  20. keyValue['E']='K';
  21. keyValue['F']='I';
  22. keyValue['G']='U';
  23. keyValue['H']='J';
  24. keyValue['I']='Y';
  25. keyValue['J']='L';
  26. keyValue['K']='T';
  27. keyValue['L']='Z';
  28. keyValue['M']='9';
  29. keyValue['N']='R';
  30. keyValue['O']='5';
  31. keyValue['P']='0';
  32. keyValue['Q']='4';
  33. keyValue['R']='E';
  34. keyValue['S']='M';
  35. keyValue['T']='X';
  36. keyValue['U']='W';
  37. keyValue['V']='V';
  38. keyValue['W']='N';
  39. keyValue['X']='B';
  40. keyValue['Y']='3';
  41. keyValue['Z']='Q';
  42. keyValue2['0']='4';
  43. keyValue2['1']='6';
  44. keyValue2['2']='O';
  45. keyValue2['3']='L';
  46. keyValue2['4']='5';
  47. keyValue2['5']='P';
  48. keyValue2['6']='M';
  49. keyValue2['7']='N';
  50. keyValue2['8']='3';
  51. keyValue2['9']='K';
  52. keyValue2['A']='7';
  53. keyValue2['B']='I';
  54. keyValue2['C']='2';
  55. keyValue2['D']='U';
  56. keyValue2['E']='Y';
  57. keyValue2['F']='H';
  58. keyValue2['G']='N';
  59. keyValue2['H']='B';
  60. keyValue2['I']='1';
  61. keyValue2['J']='8';
  62. keyValue2['K']='G';
  63. keyValue2['L']='T';
  64. keyValue2['M']='0';
  65. keyValue2['N']='F';
  66. keyValue2['O']='V';
  67. keyValue2['P']='C';
  68. keyValue2['Q']='9';
  69. keyValue2['R']='D';
  70. keyValue2['S']='R';
  71. keyValue2['T']='E';
  72. keyValue2['U']='W';
  73. keyValue2['V']='S';
  74. keyValue2['W']='X';
  75. keyValue2['X']='Z';
  76. keyValue2['Y']='A';
  77. keyValue2['Z']='Q';
  78. keyValue3['0']='N';
  79. keyValue3['1']='P';
  80. keyValue3['2']='R';
  81. keyValue3['3']='V';
  82. keyValue3['4']='I';
  83. keyValue3['5']='T';
  84. keyValue3['6']='A';
  85. keyValue3['7']='C';
  86. keyValue3['8']='Z';
  87. keyValue3['9']='G';
  88. keyValue3['N']='0';
  89. keyValue3['P']='1';
  90. keyValue3['R']='2';
  91. keyValue3['V']='3';
  92. keyValue3['I']='4';
  93. keyValue3['T']='5';
  94. keyValue3['A']='6';
  95. keyValue3['C']='7';
  96. keyValue3['Z']='8';
  97. keyValue3['G']='9';
  98. }
  99. SoftAuther::~SoftAuther(void)
  100. {
  101. }
  102. void SoftAuther::WritessFile(char* fileName,char ch[50])
  103. {
  104. FILE* pfile;
  105. pfile=fopen(fileName,"w");
  106. fprintf(pfile,ch);
  107. fclose(pfile);
  108. }
  109. void SoftAuther::ReadssFile(char* fileName,char ch[50])
  110. {
  111. FILE* pfile;
  112. pfile=fopen(fileName,"r");
  113. if(pfile==NULL) return;
  114. fscanf(pfile,"%s",ch);
  115. fclose(pfile);
  116. }
  117. char outch[50]={0};
  118. char* SoftAuther::GetKeyByNumber(string CpuNumber)
  119. {
  120. memset(outch,0,50);
  121. for(int i=0;i<CpuNumber.length();i++)
  122. {
  123. outch[i*2]=GetCharByChar(CpuNumber.at(i));
  124. outch[i*2+1]=GetCharByChar2(CpuNumber.at(i));
  125. }
  126. return outch;
  127. }
  128. char SoftAuther::GetCharByChar2(char c)
  129. {
  130. map<char, char>::iterator it_find;
  131. it_find= keyValue2.find(c);
  132. return it_find->second;
  133. }
  134. char SoftAuther::GetCharByChar(char c)
  135. {
  136. map<char, char>::iterator it_find;
  137. it_find= keyValue.find(c);
  138. return it_find->second;
  139. }
  140. char vendor_serialnumber[0x14] = { 0 };
  141. char* SoftAuther::GetCpuID()
  142. {
  143. std::array<int, 4> cpui; //#include <array>
  144. __cpuid(cpui.data(), 0x0); //cpui[0] = "funcition_id的最大值"
  145. int nIds_ = cpui[0];
  146. std::vector<std::array<int, 4>> data_; //保存遍历到的所有cpui的值
  147. for (int i=0;i<=nIds_;++i)
  148. {
  149. __cpuidex(cpui.data(), i, 0);
  150. data_.push_back(cpui);
  151. }
  152. //reinterpret_cast<int*>(vendor) //*reinterpret_cast<int*>(vendor)
  153. //索引0 0+4 0+8的值构成了CPU芯片的名称
  154. char vendor[0x20] = { 0 };
  155. *reinterpret_cast<int*>(vendor) = data_[0][1];
  156. *reinterpret_cast<int*>(vendor + 4) = data_[0][3];
  157. *reinterpret_cast<int*>(vendor + 8) = data_[0][2]; // vendor="GenuineIntel"
  158. std::string vendor_ = vendor;
  159. sprintf_s(vendor_serialnumber, sizeof(vendor_serialnumber), "%08X", data_[1][0]);
  160. return vendor_serialnumber;
  161. }
  162. bool SoftAuther::ComareData(char* id,char* psw)
  163. {
  164. char* getPas=GetKeyByNumber(id);
  165. char chcpu[50]={0};
  166. if(strlen(psw)!=28) return false;
  167. memcpy(chcpu,psw,16);
  168. char chdate[50]={0};
  169. CString Allpsd=psw;
  170. CString CodeDate = Allpsd.Mid(16,6);
  171. int idate = TransCodeToDate(CodeDate.GetBuffer(0));
  172. //sysTIme;
  173. CTime time = CTime::GetCurrentTime(); ///构造CTime对象
  174. int m_nYear = time.GetYear(); ///年
  175. m_nYear=m_nYear-2000;
  176. int m_nMonth = time.GetMonth(); ///月
  177. int m_nDay = time.GetDay(); ///日
  178. int SysTime=m_nYear*10000+m_nMonth*100+m_nDay;
  179. if(0==strcmp(getPas,chcpu))
  180. {
  181. if (SysTime<=idate)
  182. {
  183. return true;
  184. }
  185. return false;
  186. }
  187. else
  188. {
  189. return false;
  190. }
  191. }
  192. int SoftAuther::TransCodeToDate(string code)
  193. {
  194. if(code.length()<=0) return 0;
  195. char chDate[50]="0";
  196. for(int i=0;i<code.length();i++)
  197. {
  198. chDate[i]=GetCharbyChar3(code.at(i));
  199. }
  200. return atoi(chDate);
  201. }
  202. char SoftAuther::GetCharbyChar3(char c)
  203. {
  204. map<char, char>::iterator it_find;
  205. it_find= keyValue3.find(c);
  206. return it_find->second;
  207. }
  208. bool SoftAuther::CompareDate(int current,int readdate)
  209. {
  210. if(current<=readdate)
  211. {
  212. return false;
  213. }
  214. else
  215. {
  216. return true;
  217. }
  218. }
  219. void SoftAuther::ReadssDateFile(char* fileName,char ch[50])
  220. {
  221. char chhh[50];
  222. FILE* pfile;
  223. pfile=fopen(fileName,"r");
  224. if(pfile==NULL) return;
  225. fscanf(pfile,"%s",chhh);
  226. CString strAll=ch;
  227. CString strDate = strAll.Mid(16,22);
  228. memcpy(ch,strDate,strDate.GetLength());
  229. fclose(pfile);
  230. }
  231. void SoftAuther::InitAutherData(char* FileName)
  232. {
  233. char chhh[50]={0};
  234. FILE* pfile;
  235. pfile=fopen(FileName,"r");
  236. if(pfile==NULL) return;
  237. fscanf(pfile,"%s",chhh);
  238. CString m_strAutherCode = chhh;
  239. fclose(pfile);
  240. CpuCodeAuth = m_strAutherCode.Mid(0,16);
  241. CString DateCode = m_strAutherCode.Mid(16,6);
  242. CString AgentCode = m_strAutherCode.Mid(22,3);
  243. CString IvrFlowCode =m_strAutherCode.Mid(25,3);
  244. m_Date = TransCodeToDate(DateCode.GetBuffer(0));
  245. m_AgentCount = TransCodeToDate(AgentCode.GetBuffer(0));
  246. m_IvrFlowCount = TransCodeToDate(IvrFlowCode.GetBuffer(0));
  247. }