Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[292574]: DboxPassword.cpp Maximize Restore History

Download this file

DboxPassword.cpp    99 lines (80 with data), 3.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/// \file DboxPassword.cpp
//-----------------------------------------------------------------------------
#include "PasswordSafe.h"
#include "resource.h"
#include "OptionsPasswordPolicy.h"
#include "corelib/Util.h"
#include "corelib/PWCharPool.h"
#include "corelib/PWSprefs.h"
#include "DboxMain.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//-----------------------------------------------------------------------------
// generate a random password, using the default settings or user overrides
// the generated password will be copied to the clipboard. Doing
// this leaves a problem where the user can generate a random password, have
// the password copied to the clipboard and then change the password. This could
// be avoided by putting the password into the clipboard when the entry is saved
// but that would be annoying when generating a new entry.
bool
DboxMain::MakeRandomPassword( CDialog * const pDialog, CMyString& password)
{
bool is_override = (pDialog->IsDlgButtonChecked(IDC_OVERRIDE_POLICY) == BST_CHECKED);
CMyString temp;
PWSprefs *prefs = PWSprefs::GetInstance();
COptionsPasswordPolicy passwordpolicy;
passwordpolicy.m_pwlendefault = prefs->
GetPref(PWSprefs::IntPrefs::PWLenDefault);
passwordpolicy.m_pwuselowercase = prefs->
GetPref(PWSprefs::BoolPrefs::PWUseLowercase);
passwordpolicy.m_pwuseuppercase = prefs->
GetPref(PWSprefs::BoolPrefs::PWUseUppercase);
passwordpolicy.m_pwusedigits = prefs->
GetPref(PWSprefs::BoolPrefs::PWUseDigits);
passwordpolicy.m_pwusesymbols = prefs->
GetPref(PWSprefs::BoolPrefs::PWUseSymbols);
passwordpolicy.m_pwusehexdigits = prefs->
GetPref(PWSprefs::BoolPrefs::PWUseHexDigits);
passwordpolicy.m_pweasyvision = prefs->
GetPref(PWSprefs::BoolPrefs::PWEasyVision);
if (is_override) {
// Start with existing password policy
CPropertySheet optionsDlg(_T("Password Policy Override"), pDialog);
// Display COptionsPasswordPolicy page
optionsDlg.AddPage(&passwordpolicy);
optionsDlg.m_psh.dwFlags |= PSH_NOAPPLYNOW; // remove "Apply Now" button
// If the user cancels the dialog, the values will be left
// at the default values, so the password will be generated
// properly. That means we can actually ignore the return value here.
(void)optionsDlg.DoModal();
}
while(1) {
CPasswordCharPool pwchars(
passwordpolicy.m_pwlendefault,
passwordpolicy.m_pwuselowercase,
passwordpolicy.m_pwuseuppercase,
passwordpolicy.m_pwusedigits,
passwordpolicy.m_pwusesymbols,
passwordpolicy.m_pwusehexdigits,
passwordpolicy.m_pweasyvision);
temp = pwchars.MakePassword();
int nResponse;
CMyString msg;
msg = _T("The randomly generated password is: \"")
+ temp
+ _T("\" \n(without the quotes). Use it (Yes), or generate another (No)?");
nResponse = pDialog->MessageBox(msg, AfxGetAppName(),
MB_ICONQUESTION|MB_YESNOCANCEL);
if( IDYES == nResponse ) {
password = temp;
ToClipboard( password );
return true;
} else if( IDCANCEL == nResponse ) {
return false;
}
ASSERT( IDNO == nResponse );
}
}