www.pudn.com > FileGuard.zip > ChgPwdDlg.cpp


// ChgPwdDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "resource.h" 
#include "FileGuard.h" 
#include "ChgPwdDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CChgPwdDlg dialog 
 
 
CChgPwdDlg::CChgPwdDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CChgPwdDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CChgPwdDlg) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
} 
 
 
void CChgPwdDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CChgPwdDlg) 
		// NOTE: the ClassWizard will add DDX and DDV calls here 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CChgPwdDlg, CDialog) 
	//{{AFX_MSG_MAP(CChgPwdDlg) 
	ON_BN_CLICKED(IDOK, OnOk) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CChgPwdDlg message handlers 
 
void CChgPwdDlg::OnOk()  
{ 
	char lpszOldPwd[CIPHER_LEN/2], 	lpszNewPwd1[CIPHER_LEN/2], lpszNewPwd2[CIPHER_LEN/2]; 
	char lpszCipher1[CIPHER_LEN], lpszCipher2[CIPHER_LEN]; 
 
	GetDlgItemText(IDC_NEW1_PWD, lpszNewPwd1, CIPHER_LEN/2); 
	GetDlgItemText(IDC_NEW2_PWD, lpszNewPwd2, CIPHER_LEN/2); 
	if(strcmp(lpszNewPwd1, lpszNewPwd2)) 
	{ 
		AfxMessageBox("两次输入的密码不符合。"); 
		return; 
	} 
 
 
	//compare old passwords 
	GetDlgItemText(IDC_OLD_PWD, lpszOldPwd, CIPHER_LEN/2); 
	GetCipher(lpszCipher1); 
	Encrypt(lpszCipher2, lpszOldPwd); 
	if(strcmp(lpszCipher1, lpszCipher2)) 
	{ 
		AfxMessageBox("旧密码错误!"); 
		return; 
	} 
 
	Encrypt(lpszCipher1, lpszNewPwd1); 
	if(!WriteCipher(lpszCipher1)) 
		AfxMessageBox("发生错误,无法修改密码。");	//debug 
 
	CDialog::OnOK(); 
}