📄 identityvalidate.cpp
字号:
// IdentityValidate.cpp : implementation file
//
#include "stdafx.h"
#include "SuperNotepad.h"
#include "IdentityValidate.h"
#include "SuperNotepadDlg.h"
#include "ModifyPassword.h"
#include "MySingletonClass.h"
#include "CommonDefine.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int nTimes = 0;
/////////////////////////////////////////////////////////////////////////////
// CIdentityValidate dialog
CIdentityValidate::CIdentityValidate(CWnd* pParent /*=NULL*/)
: CDialog(CIdentityValidate::IDD, pParent)
{
//{{AFX_DATA_INIT(CIdentityValidate)
m_csPassword = _T("");
//}}AFX_DATA_INIT
m_csPwdPath = _T("");
m_bIsFirstTimeLogin = false;
m_bNoPwdFile = false;
}
void CIdentityValidate::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CIdentityValidate)
DDX_Control(pDX, IDC_COMBO_USER, m_csComboBoxUser);
DDX_Text(pDX, IDC_EDIT_PWD, m_csPassword);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CIdentityValidate, CDialog)
//{{AFX_MSG_MAP(CIdentityValidate)
ON_BN_CLICKED(IDC_BUTTON_QUIT, OnButtonQuit)
ON_BN_CLICKED(IDC_BUTTON_CONFIRM, OnButtonConfirm)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CIdentityValidate message handlers
BOOL CIdentityValidate::OnInitDialog()
{
CDialog::OnInitDialog();
CMySingletonClass *pMyInstance = CMySingletonClass::GetInstance();
// Add user.
m_csComboBoxUser.AddString( _T("administrator") );
//m_csComboBoxUser.AddString( _T("guest") );
m_csComboBoxUser.SetCurSel(0);
// Create MySaveFile folder.
CFileFind finder;
BOOL bFindMySaveFolder = finder.FindFile( SAVE_FILE_FOLDER );
if ( !bFindMySaveFolder )
{
BOOL bSuccCreate = CreateDirectory( SAVE_FILE_FOLDER, NULL ) ;
if ( !bSuccCreate )
{
AfxMessageBox( _T("^_^ 创建文件夹失败!") );
}
m_bIsFirstTimeLogin = true;
}
BOOL bFindPwdFile = finder.FindFile( PWD_FILE_PATH );
if ( !bFindPwdFile )
{
m_bNoPwdFile = true;
}
// Generate password in pwd.ini file.
// Open pwd.ini file.
if ( !myFile.Open( PWD_FILE_PATH, CFile::modeCreate|CFile::modeWrite|
CFile::typeText|CFile::modeNoTruncate, &Fe) )
{
AfxMessageBox( _T("^_^ 打开文件失败!") );
return FALSE;
}
// Write password to pwd.ini file.
if ( m_bIsFirstTimeLogin || m_bNoPwdFile )
{
myFile.SeekToEnd();
myFile.WriteString( _T("888") );
}
myFile.Close();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CIdentityValidate::OnButtonConfirm()
{
CSuperNotepadDlg NotepadDlg;
CMySingletonClass *pMyInstance = CMySingletonClass::GetInstance();
m_csPwdPath = PWD_FILE_PATH;
int nIndex = m_csComboBoxUser.GetCurSel();
CString csUser = _T("");
m_csComboBoxUser.GetLBText( nIndex, csUser );
if ( _T("guest") == csUser )
{
pMyInstance->m_bIsGuestUser = true;
}
if ( csUser == _T("administrator") )
{
// Open file.
if ( !myFile.Open( m_csPwdPath, CFile::modeRead, &Fe) )
{
AfxMessageBox( _T("^_^ 打开文件失败!") );
return;
}
// Get password from pwd.ini.
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_csPassword) )
{
nTimes++;
if ( 3 == nTimes )
{
AfxMessageBox( _T("^_^ 你的权限不够,请与系统管理员联系!") );
this->DestroyWindow();
return;
}
AfxMessageBox( _T("^_^ 你输入的密码是无效的!") );
GetDlgItem( IDC_EDIT_PWD )->SetFocus();
return;
}
}
this->ShowWindow( SW_HIDE );
NotepadDlg.DoModal();
}
void CIdentityValidate::OnButtonQuit()
{
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -