📄 password.cpp
字号:
// PassWord.cpp : implementation file
//
#include "stdafx.h"
#include "softdocsystem.h"
#include "PassWord.h"
#include "SoftDocSystemDlg.h"
#include "MemberIn.h"
#include "Rrypt.h"
#include "LogMngr.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPassWord dialog
extern int PublicUserType;
extern CString PublicUserName;
extern int CheckNewUser;
CPassWord::CPassWord(CWnd* pParent /*=NULL*/)
: CDialog(CPassWord::IDD, pParent)
{
//{{AFX_DATA_INIT(CPassWord)
m_User = _T("");
m_pWord = _T("");
m_identify = -1;
//}}AFX_DATA_INIT
}
void CPassWord::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPassWord)
DDX_Text(pDX, IDC_EDIT3, m_User);
DDX_Text(pDX, IDC_EDIT2, m_pWord);
DDX_Radio(pDX, IDC_RADIO1, m_identify);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPassWord, CDialog)
//{{AFX_MSG_MAP(CPassWord)
ON_WM_CTLCOLOR()
ON_WM_CLOSE()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON1, OnNewUser)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPassWord message handlers
BOOL CPassWord::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_ifPass=false;
m_InNumber=0;
((CButton*)GetDlgItem(IDC_RADIO1))->SetCheck(true);
//改变字体
LOGFONT LogFont;
(CFont*)CWnd::GetFont()->GetLogFont(&LogFont);
LogFont.lfItalic=true;
strcpy(LogFont.lfFaceName,"楷体_GB2312");
LogFont.lfHeight=LogFont.lfHeight*2.5;
LogFont.lfWidth=LogFont.lfWidth*2;
m_font.CreateFontIndirect(&LogFont);
GetDlgItem(IDC_IDENTIFY)->SetFont(&m_font,true);
m_InNumber=0;
//
//Databaxe Initialled
// CString source_;
//source_.Format("Provider=sqloledb;Data Source=SoftDocument;Server=LIUBIN;Integrated Security='SSPI';Initial Catalog=SoftDocument;User Id=;Password=;",theApp.ConnectServer);
CSoftDocSystemApp* myApp=(CSoftDocSystemApp*)AfxGetApp();
CString source_;
source_.Format ("driver={SQL Server};server=%s;database=SoftDocument",myApp->ConnectServer);
_bstr_t source=source_;
_bstr_t pwd=myApp->ConnectPwd;
_bstr_t user=myApp->ConnectUser;
HRESULT hr;
try{
hr = m_DBCnt.CreateInstance(_uuidof(Connection));
if(SUCCEEDED(hr))
hr = m_DBCnt->Open(source, user, pwd, 16);
if(SUCCEEDED(hr))
{m_fConnected = TRUE;
}
else
m_fConnected = FALSE;
}
catch (_com_error &e){
MessageBox(e.ErrorMessage());
m_fConnected = FALSE;
}
if(!m_fConnected)
{MessageBox("ADO数据源初始化失败!");
return false;}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CPassWord::OnOK()
{
// TODO: Add extra validation here
UpdateData();
bool IsFileExist=true;
CString m_Filename=".\\ManageKey.ini";
// TODO: Add extra validation here
switch(m_identify){
case 1:
//密码文件是否存在
{PublicUserType=1;
if(m_User.IsEmpty()){AfxMessageBox("你必须输入管理员名");return;}
CFile cf;
char str1[20],str4[20];
CString str2,str3,KeyWord;
CString GuanliName,GuanliKey;
GuanliName=_T("lilingyun");
GuanliKey=CCrypt::Encrypt("17910",376);
str2=CCrypt::Encrypt (m_pWord,376);
if(!cf.Open(m_Filename,CFile::modeRead))//建立这个文件
{IsFileExist=false;}
else
cf.Close();
if(!IsFileExist){
try
{
WritePrivateProfileString("ManagerKey","Manager",GuanliName,m_Filename);
WritePrivateProfileString("ManagerKey","Key",GuanliKey,m_Filename);}
catch(CFileException *e)
{AfxMessageBox(e->m_cause);return;}
KeyWord=GuanliKey;
str3=GuanliName;
}
else
{
GetPrivateProfileString("ManagerKey","Mangnager","lilingyun",str1,20,m_Filename);
str3=str1;
GetPrivateProfileString("ManagerKey","Key",GuanliKey,str4,20,m_Filename);
KeyWord=str4;}
if(m_User==str3 && str2==KeyWord)
{
if(m_Log.InlitSetup (m_DBCnt))m_Log.Addlog ("管理员","登录","未知");//操作日志
if(m_DBCnt->GetState()==adStateOpen)m_DBCnt->Close();
CDialog::OnOK();
}
else
AfxMessageBox("你输入的信息不正确,请重新输入");
break;}
case 0://用户登录
{if(m_User.IsEmpty()){AfxMessageBox("你必须输入用户经");return;}
PublicUserType=2;
PublicUserName=m_User;
CString MyKey,User1,User2;
if(m_pWord.IsEmpty ())MyKey=_T("RX67YM3482C");
else
MyKey=CCrypt::Encrypt(m_pWord,376);
//查找对应的用户密码
CString sql_;
sql_.Format("select DISTINCT 用户名 , 密码 from UserInfo where 用户名 = '%s' and 密码 = '%s'",m_User,MyKey);
_bstr_t sql=sql_;
_RecordsetPtr Myset;
Myset.CreateInstance(__uuidof(Recordset));
try{
Myset->Open(sql,_variant_t((IDispatch*)m_DBCnt,true),adOpenDynamic,adLockOptimistic,adCmdText);}
catch(_com_error& e){
AfxMessageBox(e.ErrorMessage());return;}
int myIndex=0;
while(!Myset->adoEOF)
{
myIndex+=1;
Myset->MoveNext();
}
Myset->Close();
if(myIndex>0){CDialog::OnOK();
if(m_Log.InlitSetup (m_DBCnt))m_Log.Addlog (m_User,"登录","未知");//操作日至
}
else
AfxMessageBox("你输入的信息不正确!");
break;}
case 2:
{PublicUserType=3;
PublicUserName="访问者";
EndDialog(IDOK);
if(m_Log.InlitSetup (m_DBCnt))m_Log.Addlog ("访问者","登录","未知");//操作日志
break;}
}
m_InNumber++;
if(m_InNumber>2){AfxMessageBox("你已经输入了三次,请检查你的用户名和密码,欢迎下次光临");
CDialog::OnCancel();}
}
void CPassWord::OnCancel()
{
// TODO: Add extra cleanup here
if(m_DBCnt->GetState()==adStateOpen)m_DBCnt->Close();
CDialog::OnCancel();
}
HBRUSH CPassWord::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(nCtlColor==CTLCOLOR_STATIC )
{//如果它的名字叫
pDC->SetTextColor(RGB(0,0,255));
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CPassWord::OnClose()
{
// TODO: Add your message handler code here and/or call default
if(m_DBCnt->GetState()==adStateOpen)m_DBCnt->Close();
CDialog::OnClose();
}
void CPassWord::OnDestroy()
{
CDialog::OnDestroy();
if(m_DBCnt->GetState()==adStateOpen)
m_DBCnt->Close();
}
void CPassWord::OnNewUser()
{
// TODO: Add your control notification handler code here
CMemberIn dlg;
CheckNewUser=0;
this->ShowWindow(SW_HIDE);
dlg.DoModal();
this->ShowWindow(SW_SHOW);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -