// AuthScur.cpp : implementation file // #include "stdafx.h" #include "dclient.h" #include "AuthScur.h" #include "EditKey.h" #include "commctrl.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #include "dclientDlg.h" ///////////////////////////////////////////////////////////////////////////// // CAuthSecurty property page IMPLEMENT_DYNCREATE(CAuthSecurty, CPropertyPage) CAuthSecurty::CAuthSecurty() : CPropertyPage(CAuthSecurty::IDD) { //{{AFX_DATA_INIT(CAuthSecurty) //}}AFX_DATA_INIT } CAuthSecurty::~CAuthSecurty() { } void CAuthSecurty::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAuthSecurty) DDX_Control(pDX, IDC_LIST_MAN_AUTH_KEYS, m_lstManualAuth); DDX_Control(pDX, IDC_COMBO_AUTH, m_cmbAuth); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAuthSecurty, CPropertyPage) //{{AFX_MSG_MAP(CAuthSecurty) ON_BN_CLICKED(IDC_AUTH_EDIT, OnAuthEdit) ON_BN_CLICKED(IDC_AUTH_GENERATE, OnAuthGenerate) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CAuthSecurty message handlers BOOL CAuthSecurty::OnInitDialog() { CPropertyPage::OnInitDialog(); m_cmbAuth.InsertString(0, "MUTUAL_AUTH_3P4W"); m_cmbAuth.SetCurSel(0); //////////////////////////////////////////////////////////////// LVCOLUMN lstCol; lstCol.mask = LVCF_WIDTH | LVCF_TEXT; lstCol.fmt = LVCFMT_LEFT; lstCol.cx = 50; lstCol.pszText = "Index"; lstCol.cchTextMax = 2; lstCol.iSubItem = 1; m_lstManualAuth.InsertColumn(0, &lstCol); memset(&lstCol, 0, sizeof(LVCOLUMN)); lstCol.mask = LVCF_WIDTH | LVCF_TEXT; lstCol.fmt = LVCFMT_LEFT; lstCol.cx = 160; lstCol.pszText = "Value"; lstCol.cchTextMax = 20; m_lstManualAuth.InsertColumn(1, &lstCol); //////////////////////////////////////////////////////////////// LVITEM lvItem; for(int i=0; i<8; ++i) { CString strIndex; char szValue[20]; strIndex.Format("%d", i+1); sprintf(szValue, "%I64X", m_pDclientDlg->m_ISCLAuthKeys[i]); memset(&lvItem, 0, sizeof(LVITEM)); lvItem.mask = LVIF_TEXT; lvItem.iItem = i; lvItem.iSubItem = 0; lvItem.pszText = strIndex.GetBuffer(0); lvItem.cchTextMax = 2; m_lstManualAuth.InsertItem(&lvItem); lvItem.iItem = i; lvItem.iSubItem = 1; lvItem.pszText = szValue; lvItem.cchTextMax = 20; m_lstManualAuth.SetItem(&lvItem); } m_lstManualAuth.SetItemState(m_pDclientDlg->m_lCurrentISCLAuthKey-1, LVIS_SELECTED, LVIS_SELECTED); //////////////////////////////////////////////////////////////// return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CAuthSecurty::OnAuthEdit() { CString csText; int iIndex = m_lstManualAuth.GetNextItem(-1, LVNI_SELECTED); csText = m_lstManualAuth.GetItemText(iIndex, 1); CEditKey EditKey(csText); if (EditKey.DoModal() == IDOK) { LVITEM lvItem; memset(&lvItem, 0, sizeof(LVITEM)); lvItem.mask = LVIF_TEXT; lvItem.iItem = iIndex; lvItem.iSubItem = 1; lvItem.pszText = (LPSTR)(LPCTSTR)EditKey.m_csKey; lvItem.cchTextMax = 20; m_lstManualAuth.SetItem(&lvItem); } } void CAuthSecurty::OnAuthGenerate() { srand(rand() + (unsigned)time(NULL)); for(int i=0; i<8; ++i) { char szValue[20]; __int64 RandNo64 = 0; for(int j=0; j<8; ++j) RandNo64 = (RandNo64 << 8) | (0x0FF & rand()); sprintf(szValue, "%I64X", RandNo64); m_lstManualAuth.SetItemText(i, 1, szValue); } } void CAuthSecurty::OnOK() { for(int i=0; i<8; ++i) { CString strValue = m_lstManualAuth.GetItemText(i, 1); sscanf(LPCTSTR(strValue), "%I64X", &(m_pDclientDlg->m_ISCLAuthKeys[i])); } m_pDclientDlg->m_lCurrentISCLAuthKey = m_lstManualAuth.GetNextItem(-1, LVNI_SELECTED)+1; CPropertyPage::OnOK(); }