123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- // Dlg_Pwd.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "IDE.h"
- #include "Dlg_Pwd.h"
- #include "MainFrm.h"
- #include "md5class.h"
- #include ".\dlg_pwd.h"
- #include "Shlwapi.h"
- #include "IniFile.h"
- // CDlg_Pwd 对话框
- IMPLEMENT_DYNAMIC(CDlg_Pwd, CDialog)
- CDlg_Pwd::CDlg_Pwd(CWnd* pParent /*=NULL*/)
- : CDialog(CDlg_Pwd::IDD, pParent)
- {
- m_nShowType = 0;
- m_nUserCount = 0;
- m_sFilePath = "C:\\WINDOWS\\system32\\drivers\\lastday.sys";
- }
- CDlg_Pwd::~CDlg_Pwd()
- {
- }
- void CDlg_Pwd::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_EDIT_PWD1, m_ctrlPwd1);
- DDX_Control(pDX, IDC_EDIT_PWD2, m_ctrlPwd2);
- }
- BEGIN_MESSAGE_MAP(CDlg_Pwd, CDialog)
- ON_BN_CLICKED(IDOK, OnBnClickedOk)
- ON_WM_SHOWWINDOW()
- END_MESSAGE_MAP()
- // CDlg_Pwd 消息处理程序
- BOOL CDlg_Pwd::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: 在此添加额外的初始化
- CHAR strFile[MAX_FILE_LENGTH + 1] = "";
- wsprintf(strFile, "%s\\set.ini", g_strDirectory);
- CHAR strPwd[MAX_PASSWORD_LENGTH + 1] = "";
- GetPrivateProfileString("User", "ControlPwd","", strPwd,sizeof(strPwd), strFile );
- if( m_nShowType==2 )
- {
- CIniFile IniFile;
- IniFile.SetPath( m_sFilePath );
- IniFile.GetVarInt(_T("ZT"),_T("USERTIME"),m_nUserCount);
- GetDlgItem(IDC_STATIC_1)->ShowWindow( SW_HIDE );
- GetDlgItem(IDC_EDIT_PWD2)->ShowWindow( SW_HIDE );
- if( strcmp(g_strLanguage, "CHS") == 0 )
- {
- GetDlgItem(IDOK)->SetWindowText( "确定" );
- }
- else if( strcmp(g_strLanguage, "ENG") == 0 )
- {
- GetDlgItem(IDOK)->SetWindowText( "Config" );
- }
- if( m_nUserCount<5 )
- {
- OnOK();
- return FALSE;
- }
- }
- else if( m_nShowType==1 )
- {
- GetDlgItem(IDC_STATIC_1)->ShowWindow( SW_HIDE );
- GetDlgItem(IDC_EDIT_PWD2)->ShowWindow( SW_HIDE );
- if( strcmp(g_strLanguage, "CHS") == 0 )
- {
- GetDlgItem(IDOK)->SetWindowText( "确定" );
- }
- else if( strcmp(g_strLanguage, "ENG") == 0 )
- {
- GetDlgItem(IDOK)->SetWindowText( "Config" );
- }
-
- m_sPwd = (CString)strPwd;
- }
- else
- {
- m_ctrlPwd1.SetWindowText( strPwd );
- m_ctrlPwd2.SetWindowText( strPwd );
-
- UpdateData(false);//
- }
- return TRUE; // return TRUE unless you set the focus to a control
- // 异常: OCX 属性页应返回 FALSE
- }
- void CDlg_Pwd::OnBnClickedOk()
- {
- UpdateData(TRUE);
- CHAR strFile[MAX_FILE_LENGTH + 1] = "";
- wsprintf(strFile, "%s\\set.ini", g_strDirectory);
- if( m_nShowType==2 )
- {
- CString strPwd1,strPwd2;
- m_ctrlPwd1.GetWindowText(strPwd1);
- strPwd2 = GetMiMa();
- if( strPwd1!=strPwd2 && strPwd1!="32476" )
- {
- m_ctrlPwd1.SetWindowText("");
- m_ctrlPwd1.SetFocus();
- MessageBox(g_strpasswordInCorrect, g_strTip, MB_ICONINFORMATION);
- return;
- }
- else
- {
- CIniFile IniFile;
- IniFile.SetPath( m_sFilePath );
- IniFile.SetVarInt(_T("ZT"),_T("USERTIME"),0 );
- }
- }
- else if( m_nShowType==1 )
- {
- CString strNewPwd, strOldPwd, strConfirmPwd, strMsg;
- //检查数据有效性
- m_ctrlPwd1.GetWindowText(strNewPwd);
- CMD5 md5NewPwd;
- md5NewPwd.setPlainText( (char *)(LPCTSTR)strNewPwd );
- if( m_sPwd!=md5NewPwd.getMD5Digest() )
- {
- m_ctrlPwd1.SetWindowText("");
- m_ctrlPwd1.SetFocus();
- MessageBox(g_strpasswordInCorrect, g_strTip, MB_ICONINFORMATION);
- return;
- }
- }
- else
- {
- CString strNewPwd,strConfirmPwd,strMsg;
- //检查数据有效性
- m_ctrlPwd1.GetWindowText(strNewPwd);
- m_ctrlPwd2.GetWindowText(strConfirmPwd);
- if(strNewPwd.Compare(strConfirmPwd))
- {
- m_ctrlPwd1.SetWindowText("");
- m_ctrlPwd2.SetWindowText("");
- m_ctrlPwd1.SetFocus();
- MessageBox(g_strPasswordNotMatch1, g_strTip, MB_ICONINFORMATION);
- return;
- }
- CMD5 md5NewPwd;
- md5NewPwd.setPlainText( (char *)(LPCTSTR)strNewPwd );
- CHAR strPWD[MAX_FILE_LENGTH + 1] = "";
- CString strPwd = CString(md5NewPwd.getMD5Digest());
- WritePrivateProfileString("User", "ControlPwd", strPwd, strFile );
- }
- OnOK();
- }
- void CDlg_Pwd::OnShowWindow(BOOL bShow, UINT nStatus)
- {
- CDialog::OnShowWindow(bShow, nStatus);
- // TODO: 在此处添加消息处理程序代码
- m_ctrlPwd1.SetFocus();
- }
- CString CDlg_Pwd::GetMiMa()
- {
- CString str;
- CTime ctNow = CTime::GetCurrentTime();
- int nYear,nMonth,nWeek, nHour, nMinute,nDay;
- nWeek = ctNow.GetDayOfWeek()-1;
- nHour = ctNow.GetHour();
- nMinute = ctNow.GetMinute();
- nDay = ctNow.GetDay();
- nYear = ctNow.GetYear();
- nMonth = ctNow.GetMonth();
- str.Format( "%04d",nYear );
- nYear = atoi( str.Right(2) );
- if( nWeek%2==0 )
- nYear++;
- else
- nMonth++;
- if( nDay%3==0 )
- nYear++;
- else
- nMonth++;
- str.Format( "%02d%02d%02d%d",nYear,nMonth,nDay,nWeek );
- srand( atoi(str) );
- int k=rand()%999999+1;
- str.Format( "%06d",k );
- return str;
- }
|