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

Annotation of /trunk/Src/wptPassphraseDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 22 - (hide annotations)
Wed Aug 10 11:33:35 2005 UTC (19 years, 6 months ago) by twoaday
File size: 5042 byte(s)
2005-08-06  Timo Schulz  <twoaday@freakmail.de>
 
        * wptGPGME.cpp (keycache_update): Reload OpenPGP parts
        of the secret key.
        (keycache_init): cache name of secret keyring.
        * wptKeyList.cpp (keylist_upd_key): Do not add long keyid.
        (get_key_type): Do not assume 'ultimate' means key pair.
        * wptKeyEditDlgs.cpp (diff_time): New.
        (keyedit_addsubkey_dlg_proc): Changed design and use
        diff_time. Drop checks for invalid keylength (< 1024, > 4096)
        because the combo box automatically handles this.
        * wptKeyManager.cpp (km_set_implicit_trust): Return error code.
        * wptGPG.cpp (get_backup_name): New.
        (gnupg_backup_keyrings): Rotate backup names, from 0..3.
        * wptClipImportDialog.cpp (clip_import_dlg_proc): Free memory.
        * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Use 0x short keyid and
        not the long keyid.


1 twoaday 2 /* wptPassphraseDlg.cpp - Dialog to get the passphrase
2 twoaday 4 * Copyright (C) 2001-2005 Timo Schulz
3 twoaday 2 *
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     #include <windows.h>
21    
22     #include "../resource.h"
23     #include "wptGPG.h"
24     #include "wptCommonCtl.h"
25     #include "wptContext.h"
26     #include "wptDlgs.h"
27     #include "wptNLS.h"
28     #include "wptW32API.h"
29     #include "wptUTF8.h"
30     #include "wptVersion.h"
31     #include "wptTypes.h"
32    
33    
34     struct passphrase_s {
35     char * title;
36     char pwd[256];
37 twoaday 22 int strict;
38 twoaday 2 int repeat;
39     int cancel;
40     };
41    
42    
43     static BOOL CALLBACK
44 twoaday 4 passwd_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
45 twoaday 2 {
46     static passphrase_s * pwd;
47     int nbytes;
48    
49 twoaday 4 switch (msg) {
50 twoaday 2 case WM_INITDIALOG:
51     pwd = (passphrase_s *)lparam;
52 twoaday 4 if (pwd == NULL)
53     dlg_fatal_error (dlg, "Could not get dialog param!");
54 twoaday 2 #ifndef LANG_DE
55 twoaday 4 SetWindowText (dlg, _("Passphrase Dialog"));
56 twoaday 2 #endif
57 twoaday 4 CheckDlgButton (dlg, IDC_PASSWD_HIDE, BST_CHECKED);
58     if (pwd->title)
59     SetWindowText (dlg, pwd->title);
60 twoaday 2 if (pwd->repeat)
61     SetDlgItemText (dlg, IDC_PASSWD_INFO, _("Repeat Passphrase"));
62     else
63     SetDlgItemText (dlg, IDC_PASSWD_INFO, _("Enter Passphrase"));
64 twoaday 4 SetFocus (GetDlgItem (dlg, IDC_PASSWD_PWD ));
65     center_window2 (dlg, HWND_TOPMOST);
66     center_window (dlg);
67     SetForegroundWindow (dlg);
68 twoaday 2 return FALSE;
69    
70     case WM_COMMAND:
71 twoaday 22 if (HIWORD (wparam) == BN_CLICKED &&
72     LOWORD (wparam) == IDC_PASSWD_HIDE) {
73     HWND hwnd = GetDlgItem (dlg, IDC_PASSWD_PWD);
74     int hide = IsDlgButtonChecked (dlg, IDC_PASSWD_HIDE);
75     SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0);
76     SetFocus (hwnd);
77 twoaday 2 }
78    
79 twoaday 22 switch (LOWORD (wparam)) {
80 twoaday 2 case IDOK:
81     pwd->cancel = 0;
82 twoaday 22 nbytes = GetDlgItemText( dlg, IDC_PASSWD_PWD, pwd->pwd, DIM (pwd->pwd)-1);
83     if (!nbytes)
84     strcpy (pwd->pwd, "");
85     else if (pwd->strict && check_passwd_quality (pwd->pwd, 0)) {
86     int id = msg_box (dlg, _("Your passphrase should be at least 8 characters"
87     " long\nand should contain non-alphabetic characters."
88     "\n\nStill proceed?"),
89     _("Key Generation"), MB_ICONWARNING|MB_YESNO);
90     if (id == IDNO)
91     return FALSE;
92     }
93     SetDlgItemText (dlg, IDC_PASSWD_PWD, "");
94     EndDialog (dlg, TRUE);
95 twoaday 2 return TRUE;
96    
97     case IDCANCEL:
98     pwd->cancel = 1;
99     EndDialog( dlg, FALSE );
100     return FALSE;
101     }
102     break;
103     }
104    
105     return FALSE;
106     } /* passwd_dlg_proc */
107    
108    
109 twoaday 22 char*
110     request_passphrase (const char *title, int flags, int *ret_cancel)
111 twoaday 2 {
112     passphrase_s pass;
113 twoaday 22 char *p;
114 twoaday 2
115 twoaday 22 memset (&pass, 0, sizeof (pass));
116 twoaday 2 if (title && *title) {
117     pass.title = m_strdup (title);
118     if (!pass.title)
119     BUG (0);
120     }
121 twoaday 22 pass.repeat = flags & PASSDLG_INIT? 0 : 1;
122     pass.strict = flags & PASSDLG_STRICT? 1 : 0;
123 twoaday 2 DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_PASSWD, glob_hwnd,
124     passwd_dlg_proc, (LPARAM)&pass);
125     if (pass.cancel == 1) {
126     *ret_cancel = 1;
127     return NULL;
128     }
129     p = m_strdup (pass.pwd);
130     if (!p)
131     BUG (0);
132     free_if_alloc (pass.title);
133 twoaday 22 memset (&pass, 0, sizeof (pass));
134 twoaday 2 return p;
135     } /* request_passphrase */
136    
137    
138     char *
139 twoaday 22 request_passphrase2 (const char *title, int flags, int *ret_cancel)
140 twoaday 2 {
141 twoaday 22 char *pass1, *pass2;
142 twoaday 2 int equal = 0, cancel = 0;
143    
144     *ret_cancel = 1;
145     while (!equal) {
146 twoaday 22 pass1 = request_passphrase (title, PASSDLG_INIT|flags, &cancel);
147 twoaday 2 if (cancel)
148     return NULL;
149 twoaday 22 pass2 = request_passphrase (title, PASSDLG_REPEAT, &cancel);
150 twoaday 2 if (cancel) {
151     sfree_if_alloc (pass1);
152     return NULL;
153     }
154    
155     if (strcmp (pass1, pass2)) {
156     msg_box (NULL, _("Passphrases do not match. Please try again."),
157     title, MB_INFO);
158     sfree_if_alloc (pass1);
159     sfree_if_alloc (pass2);
160     }
161     else {
162     if (is_8bit_string (pass1)) {
163     msg_box (NULL, _("The passphrase contains 8-bit characters.\n"
164     "It is not suggested to use charset specific characters."),
165     title, MB_ERR);
166     equal = 0;
167     sfree_if_alloc (pass1);
168     sfree_if_alloc (pass2);
169     }
170     else
171     equal = 1;
172     }
173     }
174     sfree_if_alloc (pass2);
175     *ret_cancel = 0;
176     return pass1;
177     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26