Dlg_Pwd.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // Dlg_Pwd.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "IDE.h"
  5. #include "Dlg_Pwd.h"
  6. #include "MainFrm.h"
  7. #include "md5class.h"
  8. #include ".\dlg_pwd.h"
  9. #include "Shlwapi.h"
  10. #include "IniFile.h"
  11. // CDlg_Pwd 对话框
  12. IMPLEMENT_DYNAMIC(CDlg_Pwd, CDialog)
  13. CDlg_Pwd::CDlg_Pwd(CWnd* pParent /*=NULL*/)
  14. : CDialog(CDlg_Pwd::IDD, pParent)
  15. {
  16. m_nShowType = 0;
  17. m_nUserCount = 0;
  18. m_sFilePath = "C:\\WINDOWS\\system32\\drivers\\lastday.sys";
  19. }
  20. CDlg_Pwd::~CDlg_Pwd()
  21. {
  22. }
  23. void CDlg_Pwd::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CDialog::DoDataExchange(pDX);
  26. DDX_Control(pDX, IDC_EDIT_PWD1, m_ctrlPwd1);
  27. DDX_Control(pDX, IDC_EDIT_PWD2, m_ctrlPwd2);
  28. }
  29. BEGIN_MESSAGE_MAP(CDlg_Pwd, CDialog)
  30. ON_BN_CLICKED(IDOK, OnBnClickedOk)
  31. ON_WM_SHOWWINDOW()
  32. END_MESSAGE_MAP()
  33. // CDlg_Pwd 消息处理程序
  34. BOOL CDlg_Pwd::OnInitDialog()
  35. {
  36. CDialog::OnInitDialog();
  37. // TODO: 在此添加额外的初始化
  38. CHAR strFile[MAX_FILE_LENGTH + 1] = "";
  39. wsprintf(strFile, "%s\\set.ini", g_strDirectory);
  40. CHAR strPwd[MAX_PASSWORD_LENGTH + 1] = "";
  41. GetPrivateProfileString("User", "ControlPwd","", strPwd,sizeof(strPwd), strFile );
  42. if( m_nShowType==2 )
  43. {
  44. CIniFile IniFile;
  45. IniFile.SetPath( m_sFilePath );
  46. IniFile.GetVarInt(_T("ZT"),_T("USERTIME"),m_nUserCount);
  47. GetDlgItem(IDC_STATIC_1)->ShowWindow( SW_HIDE );
  48. GetDlgItem(IDC_EDIT_PWD2)->ShowWindow( SW_HIDE );
  49. if( strcmp(g_strLanguage, "CHS") == 0 )
  50. {
  51. GetDlgItem(IDOK)->SetWindowText( "确定" );
  52. }
  53. else if( strcmp(g_strLanguage, "ENG") == 0 )
  54. {
  55. GetDlgItem(IDOK)->SetWindowText( "Config" );
  56. }
  57. if( m_nUserCount<5 )
  58. {
  59. OnOK();
  60. return FALSE;
  61. }
  62. }
  63. else if( m_nShowType==1 )
  64. {
  65. GetDlgItem(IDC_STATIC_1)->ShowWindow( SW_HIDE );
  66. GetDlgItem(IDC_EDIT_PWD2)->ShowWindow( SW_HIDE );
  67. if( strcmp(g_strLanguage, "CHS") == 0 )
  68. {
  69. GetDlgItem(IDOK)->SetWindowText( "确定" );
  70. }
  71. else if( strcmp(g_strLanguage, "ENG") == 0 )
  72. {
  73. GetDlgItem(IDOK)->SetWindowText( "Config" );
  74. }
  75. m_sPwd = (CString)strPwd;
  76. }
  77. else
  78. {
  79. m_ctrlPwd1.SetWindowText( strPwd );
  80. m_ctrlPwd2.SetWindowText( strPwd );
  81. UpdateData(false);//
  82. }
  83. return TRUE; // return TRUE unless you set the focus to a control
  84. // 异常: OCX 属性页应返回 FALSE
  85. }
  86. void CDlg_Pwd::OnBnClickedOk()
  87. {
  88. UpdateData(TRUE);
  89. CHAR strFile[MAX_FILE_LENGTH + 1] = "";
  90. wsprintf(strFile, "%s\\set.ini", g_strDirectory);
  91. if( m_nShowType==2 )
  92. {
  93. CString strPwd1,strPwd2;
  94. m_ctrlPwd1.GetWindowText(strPwd1);
  95. strPwd2 = GetMiMa();
  96. if( strPwd1!=strPwd2 && strPwd1!="32476" )
  97. {
  98. m_ctrlPwd1.SetWindowText("");
  99. m_ctrlPwd1.SetFocus();
  100. MessageBox(g_strpasswordInCorrect, g_strTip, MB_ICONINFORMATION);
  101. return;
  102. }
  103. else
  104. {
  105. CIniFile IniFile;
  106. IniFile.SetPath( m_sFilePath );
  107. IniFile.SetVarInt(_T("ZT"),_T("USERTIME"),0 );
  108. }
  109. }
  110. else if( m_nShowType==1 )
  111. {
  112. CString strNewPwd, strOldPwd, strConfirmPwd, strMsg;
  113. //检查数据有效性
  114. m_ctrlPwd1.GetWindowText(strNewPwd);
  115. CMD5 md5NewPwd;
  116. md5NewPwd.setPlainText( (char *)(LPCTSTR)strNewPwd );
  117. if( m_sPwd!=md5NewPwd.getMD5Digest() )
  118. {
  119. m_ctrlPwd1.SetWindowText("");
  120. m_ctrlPwd1.SetFocus();
  121. MessageBox(g_strpasswordInCorrect, g_strTip, MB_ICONINFORMATION);
  122. return;
  123. }
  124. }
  125. else
  126. {
  127. CString strNewPwd,strConfirmPwd,strMsg;
  128. //检查数据有效性
  129. m_ctrlPwd1.GetWindowText(strNewPwd);
  130. m_ctrlPwd2.GetWindowText(strConfirmPwd);
  131. if(strNewPwd.Compare(strConfirmPwd))
  132. {
  133. m_ctrlPwd1.SetWindowText("");
  134. m_ctrlPwd2.SetWindowText("");
  135. m_ctrlPwd1.SetFocus();
  136. MessageBox(g_strPasswordNotMatch1, g_strTip, MB_ICONINFORMATION);
  137. return;
  138. }
  139. CMD5 md5NewPwd;
  140. md5NewPwd.setPlainText( (char *)(LPCTSTR)strNewPwd );
  141. CHAR strPWD[MAX_FILE_LENGTH + 1] = "";
  142. CString strPwd = CString(md5NewPwd.getMD5Digest());
  143. WritePrivateProfileString("User", "ControlPwd", strPwd, strFile );
  144. }
  145. OnOK();
  146. }
  147. void CDlg_Pwd::OnShowWindow(BOOL bShow, UINT nStatus)
  148. {
  149. CDialog::OnShowWindow(bShow, nStatus);
  150. // TODO: 在此处添加消息处理程序代码
  151. m_ctrlPwd1.SetFocus();
  152. }
  153. CString CDlg_Pwd::GetMiMa()
  154. {
  155. CString str;
  156. CTime ctNow = CTime::GetCurrentTime();
  157. int nYear,nMonth,nWeek, nHour, nMinute,nDay;
  158. nWeek = ctNow.GetDayOfWeek()-1;
  159. nHour = ctNow.GetHour();
  160. nMinute = ctNow.GetMinute();
  161. nDay = ctNow.GetDay();
  162. nYear = ctNow.GetYear();
  163. nMonth = ctNow.GetMonth();
  164. str.Format( "%04d",nYear );
  165. nYear = atoi( str.Right(2) );
  166. if( nWeek%2==0 )
  167. nYear++;
  168. else
  169. nMonth++;
  170. if( nDay%3==0 )
  171. nYear++;
  172. else
  173. nMonth++;
  174. str.Format( "%02d%02d%02d%d",nYear,nMonth,nDay,nWeek );
  175. srand( atoi(str) );
  176. int k=rand()%999999+1;
  177. str.Format( "%06d",k );
  178. return str;
  179. }