00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "stdafx.h"
00027 #include "mplayerc.h"
00028 #include "AuthDlg.h"
00029
00030
00031
00032 IMPLEMENT_DYNAMIC(CAuthDlg, CDialog)
00033 CAuthDlg::CAuthDlg(CWnd* pParent )
00034 : CDialog(CAuthDlg::IDD, pParent)
00035 , m_username(_T(""))
00036 , m_password(_T(""))
00037 , m_remember(FALSE)
00038 {
00039 }
00040
00041 CAuthDlg::~CAuthDlg()
00042 {
00043 }
00044
00045 void CAuthDlg::DoDataExchange(CDataExchange* pDX)
00046 {
00047 CDialog::DoDataExchange(pDX);
00048 DDX_Control(pDX, IDC_COMBO1, m_usernamectrl);
00049 DDX_Text(pDX, IDC_COMBO1, m_username);
00050 DDX_Text(pDX, IDC_EDIT3, m_password);
00051 DDX_Check(pDX, IDC_CHECK1, m_remember);
00052 }
00053
00054 CString CAuthDlg::DEncrypt(CString str)
00055 {
00056 for(int i = 0; i < str.GetLength(); i++)
00057 str.SetAt(i, str[i]^5);
00058 return str;
00059 }
00060
00061
00062 BEGIN_MESSAGE_MAP(CAuthDlg, CDialog)
00063 ON_BN_CLICKED(IDOK, OnBnClickedOk)
00064 ON_CBN_SELCHANGE(IDC_COMBO1, OnCbnSelchangeCombo1)
00065 ON_EN_SETFOCUS(IDC_EDIT3, OnEnSetfocusEdit3)
00066 END_MESSAGE_MAP()
00067
00068
00069
00070
00071 BOOL CAuthDlg::OnInitDialog()
00072 {
00073 CDialog::OnInitDialog();
00074
00075 CWinApp* pApp = AfxGetApp();
00076
00077 if(pApp->m_pszRegistryKey)
00078 {
00079 CRegKey hSecKey(pApp->GetSectionKey(ResStr(IDS_R_LOGINS)));
00080 if(hSecKey)
00081 {
00082 int i = 0;
00083 TCHAR username[256], password[256];
00084 while(1)
00085 {
00086 DWORD unlen = countof(username);
00087 DWORD pwlen = sizeof(password);
00088 DWORD type = REG_SZ;
00089 if(ERROR_SUCCESS == RegEnumValue(
00090 hSecKey, i++, username, &unlen, 0, &type, (BYTE*)password, &pwlen))
00091 {
00092 m_logins[username] = DEncrypt(password);
00093 m_usernamectrl.AddString(username);
00094 }
00095 else
00096 {
00097 break;
00098 }
00099 }
00100 }
00101 }
00102 else
00103 {
00104 CAutoVectorPtr<TCHAR> buff;
00105 buff.Allocate(32767/sizeof(TCHAR));
00106
00107 DWORD len = GetPrivateProfileSection(
00108 ResStr(IDS_R_LOGINS), buff, 32767/sizeof(TCHAR), pApp->m_pszProfileName);
00109
00110 TCHAR* p = buff;
00111 while(*p && len > 0)
00112 {
00113 CString str = p;
00114 p += str.GetLength()+1;
00115 len -= str.GetLength()+1;
00116 CList<CString> sl;
00117 Explode(str, sl, '=', 2);
00118 if(sl.GetCount() == 2)
00119 {
00120 m_logins[sl.GetHead()] = DEncrypt(sl.GetTail());
00121 m_usernamectrl.AddString(sl.GetHead());
00122 }
00123 }
00124 }
00125
00126 m_usernamectrl.SetFocus();
00127
00128 return TRUE;
00129
00130 }
00131
00132 void CAuthDlg::OnBnClickedOk()
00133 {
00134 UpdateData();
00135
00136 if(!m_username.IsEmpty())
00137 {
00138 CWinApp* pApp = AfxGetApp();
00139 pApp->WriteProfileString(ResStr(IDS_R_LOGINS), m_username, m_remember ? DEncrypt(m_password) : _T(""));
00140 }
00141
00142 OnOK();
00143 }
00144
00145
00146 void CAuthDlg::OnCbnSelchangeCombo1()
00147 {
00148 CString username;
00149 m_usernamectrl.GetLBText(m_usernamectrl.GetCurSel(), username);
00150
00151 CString password;
00152 if(m_logins.Lookup(username, password))
00153 {
00154 m_password = password;
00155 m_remember = TRUE;
00156 UpdateData(FALSE);
00157 }
00158 }
00159
00160 void CAuthDlg::OnEnSetfocusEdit3()
00161 {
00162 UpdateData();
00163
00164 CString password;
00165 if(m_logins.Lookup(m_username, password))
00166 {
00167 m_password = password;
00168 m_remember = TRUE;
00169 UpdateData(FALSE);
00170 }
00171 }