Fixed issue #4126: Capitalize the first letter in the Push dialog
[TortoiseGit.git] / src / TortoiseProc / UserPassword.cpp
blobe9ada1160b01e43f293e5aff249cea5a58f6468b
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2013-2016, 2018-2020, 2023 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
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 this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // UserPassword.cpp : implementation file
21 #include "stdafx.h"
22 #include "resource.h"
23 #include "UserPassword.h"
25 // CUserPassword dialog
27 IMPLEMENT_DYNAMIC(CUserPassword, CStandAloneDialog)
29 CUserPassword::CUserPassword(CWnd* pParent /*=nullptr*/)
30 : CStandAloneDialog(CUserPassword::IDD, pParent)
34 CUserPassword::~CUserPassword()
36 SecureZeroMemory(&m_password, sizeof(m_password));
37 SecureZeroMemory(&m_passwordA, sizeof(m_passwordA));
40 void CUserPassword::DoDataExchange(CDataExchange* pDX)
42 CStandAloneDialog::DoDataExchange(pDX);
43 DDX_Text(pDX, IDC_USER_NAME, m_UserName);
46 BEGIN_MESSAGE_MAP(CUserPassword, CStandAloneDialog)
47 ON_BN_CLICKED(IDOK, &CUserPassword::OnBnClickedOk)
48 ON_WM_DESTROY()
49 END_MESSAGE_MAP()
51 // CUserPassword message handlers
53 BOOL CUserPassword::OnInitDialog()
55 CStandAloneDialog::OnInitDialog();
56 if (!m_URL.IsEmpty())
58 CString title;
59 this->GetWindowText(title);
60 title += L" - ";
61 title += m_URL;
62 this->SetWindowText(title);
64 GetDlgItem(IDC_USER_PASSWORD)->SendMessage(EM_SETLIMITTEXT, MAX_LENGTH_PASSWORD - 1, 0);
65 if (GetDlgItem(IDC_USER_NAME)->GetWindowTextLength())
66 GetDlgItem(IDC_USER_PASSWORD)->SetFocus();
67 else
68 GetDlgItem(IDC_USER_NAME)->SetFocus();
69 return FALSE; // we set focus to the username/password textfield
72 void CUserPassword::OnBnClickedOk()
74 UpdateData();
75 if (m_UserName.IsEmpty())
77 GetDlgItem(IDC_USER_NAME)->SetFocus();
78 ShowEditBalloon(IDC_USER_NAME, IDS_ERR_MISSINGVALUE, IDS_ERR_ERROR, TTI_ERROR);
79 return;
82 GetDlgItem(IDC_USER_PASSWORD)->GetWindowText(m_password, _countof(m_password));
84 auto lengthIncTerminator = WideCharToMultiByte(CP_UTF8, 0, m_password, static_cast<int>(wcslen(m_password)), m_passwordA, sizeof(m_passwordA) - 1, nullptr, nullptr);
85 m_passwordA[lengthIncTerminator] = '\0';
87 CStandAloneDialog::OnOK();
90 void CUserPassword::OnDestroy()
92 // overwrite password textfield contents with garbage in order to wipe the cache
93 wchar_t gargabe[MAX_LENGTH_PASSWORD];
94 wmemset(gargabe, L'*', _countof(gargabe));
95 gargabe[_countof(gargabe) - 1] = L'\0';
96 GetDlgItem(IDC_USER_PASSWORD)->SetWindowText(gargabe);
97 gargabe[0] = L'\0';
98 GetDlgItem(IDC_USER_PASSWORD)->SetWindowText(gargabe);
100 __super::OnDestroy();