From d57f9dad3b301e8819ad67136b2ca72a1e224a30 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 11 Jul 2017 21:57:54 +0300 Subject: dbx_mmap: autologin feature (#856) * dbx_mmap: autologin fiature * fix review --- plugins/Db3x_mmap/src/stdafx.h | 1 + plugins/Db3x_mmap/src/ui.cpp | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'plugins/Db3x_mmap') diff --git a/plugins/Db3x_mmap/src/stdafx.h b/plugins/Db3x_mmap/src/stdafx.h index 4291b361b8..3bd2535a54 100644 --- a/plugins/Db3x_mmap/src/stdafx.h +++ b/plugins/Db3x_mmap/src/stdafx.h @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #pragma warning(disable:4509) #include +#include #include #include #include diff --git a/plugins/Db3x_mmap/src/ui.cpp b/plugins/Db3x_mmap/src/ui.cpp index c342313ea6..1ce050dcf3 100644 --- a/plugins/Db3x_mmap/src/ui.cpp +++ b/plugins/Db3x_mmap/src/ui.cpp @@ -101,6 +101,19 @@ static INT_PTR CALLBACK sttEnterPassword(HWND hwndDlg, UINT uMsg, WPARAM wParam, case IDOK: GetDlgItemText(hwndDlg, IDC_USERPASS, param->newPass, _countof(param->newPass)); + + wchar_t tszPath[MAX_PATH]; + PathToAbsoluteW(L"\\mirandaboot.ini", tszPath); + if (GetPrivateProfileInt(L"Dbx_mmap", L"RememberPassword", 0, tszPath)) { + CREDENTIAL cred = { 0 }; + cred.Type = CRED_TYPE_GENERIC; + cred.TargetName = L"Miranda NG/Dbx_mmap"; + cred.CredentialBlobSize = mir_wstrlen(param->newPass) * sizeof(wchar_t) + sizeof(wchar_t); + cred.CredentialBlob = (LPBYTE)param->newPass; + cred.Persist = CRED_PERSIST_LOCAL_MACHINE; + CredWrite(&cred, 0); + } + EndDialog(hwndDlg, IDOK); } break; @@ -121,11 +134,17 @@ bool CDb3Mmap::EnterPassword(const BYTE *pKey, const size_t keyLen) { DlgChangePassParam param = { this }; while (true) { - // Esc pressed - if (IDOK != DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_LOGIN), 0, sttEnterPassword, (LPARAM)¶m)) - return false; + PCREDENTIAL pCred; + if (param.wrongPass == 0 && CredRead(L"Miranda NG/Dbx_mmap", CRED_TYPE_GENERIC, 0, &pCred)) { + m_crypto->setPassword(T2Utf((wchar_t*)pCred->CredentialBlob)); + CredFree(pCred); + } + else { + if (IDOK != DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_LOGIN), 0, sttEnterPassword, (LPARAM)¶m)) + return false; + m_crypto->setPassword(T2Utf(param.newPass)); + } - m_crypto->setPassword(T2Utf(param.newPass)); if (m_crypto->setKey(pKey, keyLen)) { m_bUsesPassword = true; SecureZeroMemory(¶m, sizeof(param)); -- cgit v1.2.3