⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgencryptconfg.cpp

📁 COM 组建的开发
💻 CPP
字号:
// DlgEncryptConfg.cpp : implementation file
//

#include "stdafx.h"
#include "resource.h"
#include "DlgEncryptConfg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgEncryptConfg dialog


CDlgEncryptConfg::CDlgEncryptConfg(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgEncryptConfg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgEncryptConfg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDlgEncryptConfg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgEncryptConfg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgEncryptConfg, CDialog)
	//{{AFX_MSG_MAP(CDlgEncryptConfg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgEncryptConfg message handlers

BOOL CDlgEncryptConfg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	// 初始化变量 [5/7/2008 By willing]
	m_nEncSuanFa = 0;
	
	CConfig Config;
	m_dwPwdLen = Config.GetPwdLen();
	// 获取加密类型 [5/7/2008 By willing]
	m_dwEncType = Config.GetEncryptType();
	if (1 == m_dwEncType)
	{
		// 加密时不需要密码 [5/7/2008 By willing]
		GetDlgItem(IDC_EDIT_PWD)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_PWD2)->EnableWindow(FALSE);
	}
	// 根据配置决定加密算法是否处于可选状态 [5/7/2008 By willing]
	// 发现3DES加密功能会导致无法还原,所以暂时只支持一种加密方法 [8/14/2008 By willing]
#ifndef ONLY_USE_DES
	if (0 == Config.DesIsEnable())
	{
		// 禁用 [5/7/2008 By willing]
		EnableButton(IDC_RADIO_DES,FALSE);
	}
	if (0 == Config.Des3IsEnable())
	{
		// 禁用 [5/7/2008 By willing]
		EnableButton(IDC_RADIO_3DES,FALSE);
	}
#endif
	char szTemp[MAX_PATH]={0};
	if (1 == m_dwEncType)
	{
		sprintf(szTemp,"    管理员已设置加密时禁止使用密码!",m_dwPwdLen);
	}else{
		sprintf(szTemp,"    密码长度至少%d位,请妥善保管您的密码,遗失密码可能导致该文件无法恢复!",m_dwPwdLen);
	}
	SetDlgItemText(IDC_MSG,szTemp);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
// 使指定的按钮有效或无效 [5/7/2008 By willing]
void CDlgEncryptConfg::EnableButton(int nID,BOOL bEnable)
{
	CButton* ptrButton = (CButton*)GetDlgItem(nID);
	if (NULL == ptrButton)
	{
		return;
	}
	ptrButton->EnableWindow(bEnable);
	return;
}

void CDlgEncryptConfg::OnOK() 
{
	// TODO: Add extra validation here
	if (CheckInput() == FALSE)
	{
		return;
	}
	CDialog::OnOK();
}
// 校验用户输入 [5/7/2008 By willing]
BOOL CDlgEncryptConfg::CheckInput()
{
	CString strMsg = "";
	if (1 != m_dwEncType)
	{
		// 校验密码长度 [5/7/2008 By willing]
		GetDlgItemText(IDC_EDIT_PWD,m_strPwd);
		if (m_strPwd.GetLength() < (int)m_dwPwdLen)
		{
			strMsg.Format("密码长度最小为%d!",m_dwPwdLen);
			MessageBox(strMsg,"提示",MB_ICONINFORMATION|MB_OK);
			GetDlgItem(IDC_EDIT_PWD)->SetFocus();
			return FALSE;
		}
		if (m_strPwd.GetLength() > 30)
		{
			strMsg.Format("密码最多不能超过30字符!",m_dwPwdLen);
			MessageBox(strMsg,"提示",MB_ICONINFORMATION|MB_OK);
			GetDlgItem(IDC_EDIT_PWD)->SetFocus();
			return FALSE;
		}
		// 对密码中的非法字符的判断 [5/7/2008 By willing]
		if ((m_strPwd.Find('<',0) != -1)||(m_strPwd.Find('&',0) != -1))
		{
			strMsg = "密码中不能含有特殊字符 < &";
			m_strPwd = "";
			MessageBox(strMsg,"提示",MB_ICONINFORMATION|MB_OK);
			SetDlgItemText(IDC_EDIT_PWD,"");
			SetDlgItemText(IDC_EDIT_PWD2,"");
			GetDlgItem(IDC_EDIT_PWD)->SetFocus();
			return FALSE;
		}
		// 校验两次输入的密码是否相同 [5/7/2008 By willing]
		CString strPwd2 = "";
		GetDlgItemText(IDC_EDIT_PWD2,strPwd2);
		if (m_strPwd != strPwd2)
		{
			strMsg = _T("两次输入的密码不正确!");
			MessageBox(strMsg,"提示",MB_ICONINFORMATION|MB_OK);
			SetDlgItemText(IDC_EDIT_PWD2,"");
			GetDlgItem(IDC_EDIT_PWD2)->SetFocus();
			return FALSE;
		}
	}
#ifndef ONLY_USE_DES
	// 校验加密算法的选择 [5/7/2008 By willing]
	int nFlag = GetCheckedRadioButton(IDC_RADIO_DES,IDC_RADIO_3DES);
	if (IDC_RADIO_DES == nFlag)
	{
		m_nEncSuanFa = ENCTYPE_DES;	
	}else if(IDC_RADIO_3DES == nFlag){
		m_nEncSuanFa = ENCTYPE_3DES;
	}
	if (0 == m_nEncSuanFa)
	{
		MessageBox("请选择加密算法!","提示",MB_ICONINFORMATION|MB_OK);
		return FALSE;
	}
#else
	m_nEncSuanFa = ENCTYPE_DES;
#endif
	return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -