186 lines
4.6 KiB
C++
186 lines
4.6 KiB
C++
// DLG_Dog_Create.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "smsmanager.h"
|
|
#include "DLG_Dog_Create.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// DLG_Dog_Create dialog
|
|
|
|
|
|
DLG_Dog_Create::DLG_Dog_Create(CWnd* pParent /*=NULL*/)
|
|
: CDialog(DLG_Dog_Create::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(DLG_Dog_Create)
|
|
m_strLoginName = _T("");
|
|
//}}AFX_DATA_INIT
|
|
}
|
|
|
|
|
|
void DLG_Dog_Create::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(DLG_Dog_Create)
|
|
DDX_Control(pDX, IDC_DOG_LOGINNAME, m_E_LoginName);
|
|
DDX_Text(pDX, IDC_DOG_LOGINNAME, m_strLoginName);
|
|
DDV_MaxChars(pDX, m_strLoginName, 15);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(DLG_Dog_Create, CDialog)
|
|
//{{AFX_MSG_MAP(DLG_Dog_Create)
|
|
ON_BN_CLICKED(IDC_DOG_CREATE, OnDogCreate)
|
|
ON_BN_CLICKED(IDC_DOG_READ, OnDogRead)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// DLG_Dog_Create message handlers
|
|
|
|
BOOL DLG_Dog_Create::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
// TODO: Add extra initialization here
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
void DLG_Dog_Create::OnDogCreate()
|
|
{
|
|
if ( !UpdateData(true) )
|
|
return ;
|
|
|
|
if ( m_strLoginName.GetLength()<=0 )
|
|
{
|
|
MessageBox( _T("请先输入登录用户名!") , _T("错误") , MB_ICONWARNING );
|
|
return ;
|
|
}
|
|
char DevicePath[512]={0};
|
|
if(FindPort(0,DevicePath)!=0)
|
|
{
|
|
MessageBox(_T("未找到简单型加密锁,请确认加密狗已插入并且已安装驱动程序!"),_T("错误"),MB_ICONWARNING);
|
|
return ;
|
|
}
|
|
|
|
char szLoginName2[512]={0};
|
|
#ifdef _UNICODE
|
|
strcpy( szLoginName2 , CW2A(m_strLoginName) );
|
|
#else
|
|
strcpy( szLoginName2 , m_strLoginName );
|
|
#endif
|
|
char szLoginName[512]={0};
|
|
char szKey[512]={0};
|
|
strcpy(szKey,"mobset");
|
|
long lLen=sizeof(szLoginName);
|
|
CDes des;
|
|
|
|
if (!des.Encrypt(szLoginName2,strlen(szLoginName2),szLoginName,lLen,szKey,8) )
|
|
{
|
|
MessageBox(_T("加密失败!"),_T("错误"),MB_ICONWARNING);
|
|
return ;
|
|
}
|
|
|
|
int iRet=0;
|
|
//设置加密狗密码
|
|
char strOldWPasswd[32],strOldRPasswd[32],strNewWPasswd[32],strNewRPasswd[32];
|
|
sprintf( strOldWPasswd, "%X",DOG_OLDWPASSWD );
|
|
sprintf( strOldRPasswd, "%X",DOG_OLDRPASSWD );
|
|
sprintf( strNewWPasswd, "%X",DOG_NEWWPASSWD );
|
|
sprintf( strNewRPasswd, "%X",DOG_NEWRPASSWD );
|
|
|
|
|
|
//设置写密码
|
|
iRet = SetWritePassword(strOldWPasswd,strOldWPasswd,
|
|
strNewWPasswd,strNewWPasswd, DevicePath);
|
|
|
|
short DogAddr = 3;
|
|
int DogBytes = strlen(szLoginName);
|
|
|
|
iRet = YWriteString2((char*)&DogBytes, DogAddr,sizeof(DogBytes),strNewWPasswd,strNewWPasswd,DevicePath);
|
|
DogAddr += sizeof(DogBytes);
|
|
iRet = YWriteString2(szLoginName, DogAddr,DogBytes,strNewWPasswd,strNewWPasswd,DevicePath);
|
|
if ( iRet !=0 )
|
|
{
|
|
MessageBox( _T("写加密狗失败,请检查!"),_T("错误"),MB_ICONWARNING );
|
|
return ;
|
|
}
|
|
else
|
|
{
|
|
MessageBox( _T("恭喜,恭喜!写狗成功!"),_T("成功"),MB_ICONINFORMATION );
|
|
return ;
|
|
}
|
|
return ;
|
|
}
|
|
|
|
void DLG_Dog_Create::OnDogRead()
|
|
{
|
|
char DevicePath[260]={0};
|
|
if(FindPort(0,DevicePath)!=0)
|
|
{
|
|
MessageBox(_T("未找到简单型加密锁,请确认加密狗已插入并且已安装驱动程序!"),_T("错误"),MB_ICONWARNING);
|
|
return ;
|
|
}
|
|
|
|
int iRet=0;
|
|
//设置加密狗密码
|
|
char strOldWPasswd[32],strOldRPasswd[32],strNewWPasswd[32],strNewRPasswd[32];
|
|
sprintf( strOldWPasswd, "%X",DOG_OLDWPASSWD );
|
|
sprintf( strOldRPasswd, "%X",DOG_OLDRPASSWD );
|
|
sprintf( strNewWPasswd, "%X",DOG_NEWWPASSWD );
|
|
sprintf( strNewRPasswd, "%X",DOG_NEWRPASSWD );
|
|
|
|
char szLoginName[256]={0};
|
|
short DogAddr = 3;
|
|
int DogBytes = 0;
|
|
|
|
iRet = YReadString2((char*)&DogBytes, DogAddr,sizeof(DogBytes),strOldRPasswd,strOldRPasswd,DevicePath);
|
|
if ( iRet!=0 && DogBytes>0 && DogBytes<100 )
|
|
{
|
|
MessageBox( _T("读取加密狗错误,请检查!"),_T("错误"),MB_ICONWARNING );
|
|
return ;
|
|
}
|
|
|
|
DogAddr += sizeof(DogBytes);
|
|
iRet = YReadString2(szLoginName, DogAddr,DogBytes,strOldRPasswd,strOldRPasswd,DevicePath);
|
|
if ( iRet!=0 )
|
|
{
|
|
MessageBox( _T("读取加密狗错误,请检查!"),_T("错误"),MB_ICONWARNING );
|
|
return ;
|
|
}
|
|
|
|
char szLoginName2[256]={0};
|
|
char szKey[256]={0};
|
|
strcpy(szKey,"mobset");
|
|
long lLen=sizeof(szLoginName2);
|
|
CDes des;
|
|
if (!des.Decrypt(szLoginName,strlen(szLoginName),szLoginName2,lLen,szKey,8) )
|
|
{
|
|
MessageBox(_T("解密失败!"),_T("错误"),MB_ICONWARNING);
|
|
return ;
|
|
}
|
|
|
|
#ifdef _UNICODE
|
|
m_strLoginName = CA2W(szLoginName2);
|
|
#else
|
|
m_strLoginName = szLoginName2;
|
|
#endif
|
|
|
|
UpdateData(false);
|
|
|
|
CString str;
|
|
str.Format( _T("读取加密狗成功,登录名为:%s"),szLoginName2);
|
|
MessageBox( str , _T("成功") , MB_ICONINFORMATION );
|
|
|
|
return ;
|
|
}
|