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

📄 dialogsetsecret.cpp

📁 上次发布的通讯簿必须用VC.NET运行,如果大家没有装VC.NET,那么就可能不能运行此程序了.对此,我非常抱歉! 为了让大家都能运行,我整理出了源代码和应用程序,即使你的机子上没有任何编译器,也可
💻 CPP
字号:
// DialogSetSecret.cpp : 实现文件
//

#include "stdafx.h"
#include "通讯簿2.0.h"
#include "DialogSetSecret.h"
#include ".\dialogsetsecret.h"


// CDialogSetSecret 对话框

IMPLEMENT_DYNAMIC(CDialogSetSecret, CDialog)
CDialogSetSecret::CDialogSetSecret(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogSetSecret::IDD, pParent)
	, m_SecretOld(_T(""))
	, m_SecretNew(_T(""))
	, m_SecretAgain(_T(""))
	, secretold(_T(""))
	, length(0)
	, length1(0)
	, length2(0)
{
}

CDialogSetSecret::~CDialogSetSecret()
{
}

void CDialogSetSecret::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDITOLD, m_SecretOld);
	DDX_Text(pDX, IDC_EDITNEW, m_SecretNew);
	DDX_Text(pDX, IDC_EDITAGAIN, m_SecretAgain);
}


BEGIN_MESSAGE_MAP(CDialogSetSecret, CDialog)
	ON_BN_CLICKED(IDOK, OnBnClickedOk)
END_MESSAGE_MAP()


// CDialogSetSecret 消息处理程序

void CDialogSetSecret::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	CFile file("Index",CFile::modeRead);
    CArchive arload( &file, CArchive::load) ;
	LoadSecret(arload);
	file.Close();

	UpdateData(true);
	if(m_SecretOld == secretold)
	{
		if(m_SecretNew == m_SecretAgain)
		{
			secretold = m_SecretNew;
			CFile file("Index",CFile::modeWrite|CFile::modeCreate);
	        CArchive arsave( &file, CArchive::store) ;
			SaveSecret(arsave);
			AfxMessageBox("新密码设置成功!");
		}
		else
		{
			AfxMessageBox("两次新密码输入不一致,请重新输入!");
			m_SecretNew.Empty();
			m_SecretAgain.Empty();
			UpdateData(false);
			return;
			
		}
	}
	else{
		AfxMessageBox("原密码输入错误,请重新输入!");
		m_SecretOld.Empty();
		m_SecretNew.Empty();
		m_SecretAgain.Empty();
		UpdateData(false);
		return;
	}
	OnOK();
}

void CDialogSetSecret::SaveSecret(CArchive& ar)
{
	length2 = secretold.GetLength();
	CString str = Randdata() + secretold;
	length1=length;
	str += Randdata();
	ar<<length1;
	ar<<length2;
	ar<<str;
	return;
}

void CDialogSetSecret::LoadSecret(CArchive& ar)
{
	ar>>length1;
	ar>>length2;
	ar>>secretold;
	secretold = secretold.Mid(length1,length2);
	return;
}


CString CDialogSetSecret::Randdata(void)
{
	CString m_oBject;
	srand( (unsigned)time( NULL ) );
    length = rand();  
	while(length<1000)
	{
		length = rand();
	}
	for(int i = 0;i< length;i++)
	{
		int tempData = rand()%66;
		m_oBject.Insert(i,'0'+tempData);
	}
	return m_oBject;
}

⌨️ 快捷键说明

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