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

Annotation of /trunk/Src/wptPassphraseDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (hide annotations)
Sun Feb 6 11:11:40 2005 UTC (20 years ago) by twoaday
File size: 4590 byte(s)
2005-02-02  Timo Schulz  <twoaday@freakmail.de>
                                                                                                                            
        * wptPassphraseDlg.cpp (passwd_dlg_proc): use center_window2, otherwise
        it is invisible.
        * wptPassphraseCB.cpp (passphrase_callback_proc): Do not cache symmetric
        passphrases.
        * Enable the progress dialog for symmetric encryption.
        * wptFileManager.cpp (fm_check_file_type): Also check for 'SYMKEYENC' in
        FM_ENCRYPT mode.
        * WinPT.cpp (WinMain): SETUP_EXISTING implemented.
        * wptGPGPrefsDlg.cpp (gpgprefs_dlg_proc): Reset 'Locale directory' when
        no value is entered.
                                                                                                                            
2005-02-04  Timo Schulz  <twoaday@freakmail.de>
                                                                                                                            
        * wptProgressDlg.cpp (progress_cb_thread): Set root window if available.
        If the progress window survives by accident, it will be closed when the
        File Manager (root window) is closed.
                                                                                                                            


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26