2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
23 // AuthDlg.cpp : implementation file
32 IMPLEMENT_DYNAMIC(CAuthDlg
, CDialog
)
33 CAuthDlg::CAuthDlg(CWnd
* pParent
/*=NULL*/)
34 : CDialog(CAuthDlg::IDD
, pParent
)
45 void CAuthDlg::DoDataExchange(CDataExchange
* pDX
)
47 CDialog::DoDataExchange(pDX
);
48 DDX_Control(pDX
, IDC_COMBO1
, m_usernamectrl
);
49 DDX_Text(pDX
, IDC_COMBO1
, m_username
);
50 DDX_Text(pDX
, IDC_EDIT3
, m_password
);
51 DDX_Check(pDX
, IDC_CHECK1
, m_remember
);
54 CString
CAuthDlg::DEncrypt(CString str
)
56 for(int i
= 0; i
< str
.GetLength(); i
++)
57 str
.SetAt(i
, str
[i
]^5);
62 BEGIN_MESSAGE_MAP(CAuthDlg
, CDialog
)
63 ON_BN_CLICKED(IDOK
, OnBnClickedOk
)
64 ON_CBN_SELCHANGE(IDC_COMBO1
, OnCbnSelchangeCombo1
)
65 ON_EN_SETFOCUS(IDC_EDIT3
, OnEnSetfocusEdit3
)
69 // CAuthDlg message handlers
71 BOOL
CAuthDlg::OnInitDialog()
73 CDialog::OnInitDialog();
75 CWinApp
* pApp
= AfxGetApp();
77 if(pApp
->m_pszRegistryKey
)
79 CRegKey
hSecKey(pApp
->GetSectionKey(ResStr(IDS_R_LOGINS
)));
83 TCHAR username
[256], password
[256];
86 DWORD unlen
= countof(username
);
87 DWORD pwlen
= sizeof(password
);
89 if(ERROR_SUCCESS
== RegEnumValue(
90 hSecKey
, i
++, username
, &unlen
, 0, &type
, (BYTE
*)password
, &pwlen
))
92 m_logins
[username
] = DEncrypt(password
);
93 m_usernamectrl
.AddString(username
);
104 CAutoVectorPtr
<TCHAR
> buff
;
105 buff
.Allocate(32767/sizeof(TCHAR
));
107 DWORD len
= GetPrivateProfileSection(
108 ResStr(IDS_R_LOGINS
), buff
, 32767/sizeof(TCHAR
), pApp
->m_pszProfileName
);
114 p
+= str
.GetLength()+1;
115 len
-= str
.GetLength()+1;
116 CAtlList
<CString
> sl
;
117 Explode(str
, sl
, '=', 2);
118 if(sl
.GetCount() == 2)
120 m_logins
[sl
.GetHead()] = DEncrypt(sl
.GetTail());
121 m_usernamectrl
.AddString(sl
.GetHead());
126 m_usernamectrl
.SetFocus();
128 return TRUE
; // return TRUE unless you set the focus to a control
129 // EXCEPTION: OCX Property Pages should return FALSE
132 void CAuthDlg::OnBnClickedOk()
136 if(!m_username
.IsEmpty())
138 CWinApp
* pApp
= AfxGetApp();
139 pApp
->WriteProfileString(ResStr(IDS_R_LOGINS
), m_username
, m_remember
? DEncrypt(m_password
) : _T(""));
146 void CAuthDlg::OnCbnSelchangeCombo1()
149 m_usernamectrl
.GetLBText(m_usernamectrl
.GetCurSel(), username
);
152 if(m_logins
.Lookup(username
, password
))
154 m_password
= password
;
160 void CAuthDlg::OnEnSetfocusEdit3()
165 if(m_logins
.Lookup(m_username
, password
))
167 m_password
= password
;