/[winpt]/trunk/Src/wptPassphraseDlg.cpp
ViewVC logotype

Annotation of /trunk/Src/wptPassphraseDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 130 - (hide annotations)
Fri Dec 30 14:06:39 2005 UTC (19 years, 2 months ago) by twoaday
File size: 5571 byte(s)
2005-12-29  Timo Schulz  <ts@g10code.com>
  
        * wptKeygenDlg.cpp (keygen_dlg_proc): Request passphrase dynamically.
        (gpg_genkey_params): Simplified.
        * wptPreferencesDlg.cpp (prefs_dlg_proc): Fix problem with mutal
        exclusion of the dialog items.
        * wptAboutDlgs.cpp (about_winpt_dlg_proc): Allow to use ESC to
        quit the dialog.
        * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Likewise.
        * wptMDSumDlg.cpp (mdsum_dlg_proc): Handle WM_SYSCOMMAND.
        (id2algo): New.

Prepare 0.11.4 release.


1 werner 36 /* wptPassphraseDlg.cpp - Dialog to get the passphrase
2     * Copyright (C) 2001-2005 Timo Schulz
3     *
4     * This file is part of WinPT.
5     *
6     * WinPT is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * WinPT is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with WinPT; if not, write to the Free Software Foundation,
18     * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19     */
20     #ifdef HAVE_CONFIG_H
21     #include <config.h>
22     #endif
23    
24     #include <windows.h>
25    
26 werner 47 #include "resource.h"
27 werner 36 #include "wptGPG.h"
28     #include "wptCommonCtl.h"
29     #include "wptContext.h"
30     #include "wptDlgs.h"
31     #include "wptNLS.h"
32     #include "wptW32API.h"
33     #include "wptUTF8.h"
34     #include "wptVersion.h"
35     #include "wptTypes.h"
36    
37    
38     struct passphrase_s {
39     char *title; /* title of the dialog. */
40     char pwd[256]; /* the actual passphrase. */
41     int strict; /* do a simple check how good the passphrase is. */
42     int repeat; /* Indicate last try was wrong. */
43     int cancel; /* 1 if user cancelled operation. */
44     };
45    
46    
47     /* Dialog procedure to request a passphrase from the user. */
48     static BOOL CALLBACK
49     passwd_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
50     {
51     static passphrase_s * pwd;
52     int nbytes;
53    
54     switch (msg) {
55     case WM_INITDIALOG:
56     pwd = (passphrase_s *)lparam;
57     if (pwd == NULL)
58     dlg_fatal_error (dlg, "Could not get dialog param!");
59     SetWindowText (dlg, _("Passphrase Dialog"));
60     CheckDlgButton (dlg, IDC_PASSWD_HIDE, BST_CHECKED);
61     if (pwd->title)
62     SetWindowText (dlg, pwd->title);
63     if (pwd->repeat)
64     SetDlgItemText (dlg, IDC_PASSWD_INFO, _("Repeat Passphrase"));
65     else
66     SetDlgItemText (dlg, IDC_PASSWD_INFO, _("Enter Passphrase"));
67 twoaday 78 SetDlgItemText (dlg, IDC_PASSWD_HIDE, _("&Hide Typing"));
68 twoaday 101 SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
69 werner 36 SetFocus (GetDlgItem (dlg, IDC_PASSWD_PWD ));
70     center_window2 (dlg, NULL, HWND_TOPMOST);
71     center_window (dlg, NULL);
72     SetForegroundWindow (dlg);
73     return FALSE;
74    
75     case WM_COMMAND:
76     if (HIWORD (wparam) == BN_CLICKED &&
77     LOWORD (wparam) == IDC_PASSWD_HIDE) {
78     HWND hwnd = GetDlgItem (dlg, IDC_PASSWD_PWD);
79     int hide = IsDlgButtonChecked (dlg, IDC_PASSWD_HIDE);
80     SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0);
81     SetFocus (hwnd);
82     }
83    
84     switch (LOWORD (wparam)) {
85     case IDOK:
86     pwd->cancel = 0;
87 twoaday 130 nbytes = GetDlgItemText (dlg, IDC_PASSWD_PWD, pwd->pwd, DIM (pwd->pwd)-1);
88 werner 36 if (!nbytes)
89     strcpy (pwd->pwd, "");
90     else if (pwd->strict && check_passwd_quality (pwd->pwd, 0)) {
91     int id = msg_box (dlg, _("Your passphrase should be at least 8 characters"
92     " long\nand should contain non-alphabetic characters."
93     "\n\nStill proceed?"),
94     _("Key Generation"), MB_ICONWARNING|MB_YESNO);
95     if (id == IDNO)
96     return TRUE;
97     }
98     SetDlgItemText (dlg, IDC_PASSWD_PWD, "");
99     EndDialog (dlg, TRUE);
100     return TRUE;
101    
102     case IDCANCEL:
103     pwd->cancel = 1;
104     EndDialog (dlg, FALSE);
105     return TRUE;
106     }
107     break;
108     }
109    
110     return FALSE;
111     }
112    
113    
114     /* Request a passphrase from the user. @title is the title of the
115     dialog and @ret_cancel is true if user cancelled the operation.
116     Return value: the passphrase or NUL for an error. */
117     char*
118     request_passphrase (const char *title, int flags, int *ret_cancel)
119     {
120     passphrase_s pass;
121     char *p;
122    
123     memset (&pass, 0, sizeof (pass));
124     if (title && *title) {
125     pass.title = m_strdup (title);
126     if (!pass.title)
127     BUG (0);
128     }
129     pass.repeat = flags & PASSDLG_INIT? 0 : 1;
130     pass.strict = flags & PASSDLG_STRICT? 1 : 0;
131     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_PASSWD, glob_hwnd,
132     passwd_dlg_proc, (LPARAM)&pass);
133     if (pass.cancel == 1) {
134     *ret_cancel = 1;
135     return NULL;
136     }
137     p = m_strdup (pass.pwd);
138     if (!p)
139     BUG (0);
140     free_if_alloc (pass.title);
141     memset (&pass, 0, sizeof (pass));
142     return p;
143     }
144    
145    
146     /* Request a passphrase from the user but also confirm the passphrase
147     to make sure there is no typo. Arguments same as in the normal version
148     of the function. */
149     char*
150     request_passphrase2 (const char *title, int flags, int *ret_cancel)
151     {
152     char *pass1, *pass2;
153     int equal = 0, cancel = 0;
154    
155     *ret_cancel = 1;
156     while (!equal) {
157     pass1 = request_passphrase (title, PASSDLG_INIT|flags, &cancel);
158     if (cancel)
159     return NULL;
160     pass2 = request_passphrase (title, PASSDLG_REPEAT, &cancel);
161     if (cancel) {
162     sfree_if_alloc (pass1);
163     return NULL;
164     }
165    
166     if (strcmp (pass1, pass2)) {
167     msg_box (NULL, _("Passphrases do not match. Please try again."),
168     title, MB_INFO);
169     sfree_if_alloc (pass1);
170     sfree_if_alloc (pass2);
171     }
172     else {
173     if (is_8bit_string (pass1)) {
174     msg_box (NULL, _("The passphrase contains 8-bit characters.\n"
175     "It is not suggested to use charset specific characters."),
176     title, MB_ERR);
177     equal = 0;
178     sfree_if_alloc (pass1);
179     sfree_if_alloc (pass2);
180     }
181     else
182     equal = 1;
183     }
184     }
185     sfree_if_alloc (pass2);
186     *ret_cancel = 0;
187     return pass1;
188     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26