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

📄 modifypassword.cpp

📁 非比寻常的超级记事本 1.日历控件的使用 2.托盘技术 3.开机后应用程序自动启动 4.非模态对话框的创建和关闭 5.Singleton类的使用 6.文件的读写 7.弹出式菜单的创建
💻 CPP
字号:
// ModifyPassword.cpp : implementation file
//

#include "stdafx.h"
#include "SuperNotepad.h"
#include "ModifyPassword.h"
#include "CommonDefine.h"

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

int nLoginTimes = 0;
/////////////////////////////////////////////////////////////////////////////
// CModifyPassword dialog


CModifyPassword::CModifyPassword(CWnd* pParent /*=NULL*/)
	: CDialog(CModifyPassword::IDD, pParent)
{
	//{{AFX_DATA_INIT(CModifyPassword)
	m_csOldPwd = _T("");
	m_csNewPwd = _T("");
	m_csConfirmNewPwd = _T("");
	//}}AFX_DATA_INIT

    m_csPwdPath = _T("");
}


void CModifyPassword::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CModifyPassword)
	DDX_Text(pDX, IDC_EDIT_OLD_PWD, m_csOldPwd);
	DDX_Text(pDX, IDC_EDIT_NEW_PWD, m_csNewPwd);
	DDX_Text(pDX, IDC_EDIT_CONFIRM_NEW_PWD, m_csConfirmNewPwd);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CModifyPassword, CDialog)
	//{{AFX_MSG_MAP(CModifyPassword)
	ON_BN_CLICKED(IDC_CONFIRM_BUTTON, OnConfirmButton)
	ON_BN_CLICKED(IDC_QUIT_BUTTON, OnQuitButton)
	ON_EN_KILLFOCUS(IDC_EDIT_OLD_PWD, OnKillfocusEditOldPwd)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CModifyPassword message handlers
BOOL CModifyPassword::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	//GetDlgItem( IDC_EDIT_NEW_PWD )->EnableWindow( FALSE );
    //GetDlgItem( IDC_EDIT_CONFIRM_NEW_PWD )->EnableWindow( FALSE );
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CModifyPassword::OnKillfocusEditOldPwd() 
{    
	m_csPwdPath = PWD_FILE_PATH;    
	
	// Open file.
	if ( !myFile.Open( m_csPwdPath, CFile::modeRead, &Fe) )
	{
		AfxMessageBox( _T("^_^ 打开文件失败!") );
		return;		
	}
    
    // Get old password from pwd.ini file. 
	CString csPwd = _T("");
	CString csAdministratorPwd = _T("");
	while ( myFile.ReadString(csPwd) )
	{
		csAdministratorPwd = csPwd;
	}  
	
	// Close file.
	myFile.Close();

	UpdateData();

	csAdministratorPwd.TrimLeft();
	csAdministratorPwd.TrimRight();    		

	if ( 0 != csAdministratorPwd.Compare(m_csOldPwd) )			 
	{
		nLoginTimes++;
		if ( 3 == nLoginTimes )
		{
            AfxMessageBox( _T("^_^ 你的权限不够,请与系统管理员联系!") );
            this->DestroyWindow();
            AfxGetApp()->m_pMainWnd->DestroyWindow();
            return;
		}

        AfxMessageBox( _T("^_^ 你输入的旧密码是无效的!") ); 
        GetDlgItem( IDC_EDIT_OLD_PWD )->SetFocus();
        return;
	}      	
}

void CModifyPassword::OnConfirmButton() 
{
    UpdateData();

    if ( 0 != m_csNewPwd.Compare(m_csConfirmNewPwd) )
    {
        AfxMessageBox( _T("^_^ 你两次输入的新密码不一致!") );
    } 
    else
    {
        // Write new password to pwd.ini file.
        m_csPwdPath = PWD_FILE_PATH;
    
	    // Open file.
        if ( !myFile.Open( m_csPwdPath, CFile::modeCreate|CFile::modeWrite|
             CFile::typeText|CFile::modeNoTruncate, &Fe) )
        {
            AfxMessageBox( _T("^_^ 打开文件失败!") );
		    return;		
	    }

	    // Write file.
	    if ( 0 != myFile.GetLength() )
	    {
            myFile.SetLength( 0 );            		    		
	    }
        myFile.SeekToEnd();  
		myFile.WriteString( m_csNewPwd );

        // Close file.
	    myFile.Close();
        
        AfxMessageBox( _T("^_^ 恭喜你,密码修改成功!") );
		CModifyPassword::OnQuitButton();            
    }  	
}

void CModifyPassword::OnQuitButton() 
{
	CDialog::OnCancel();	
}




⌨️ 快捷键说明

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