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

Annotation of /trunk/Src/wptPINDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 225 - (hide annotations)
Tue Jun 6 13:37:59 2006 UTC (18 years, 8 months ago) by twoaday
File size: 3642 byte(s)


1 werner 36 /* wptPINDlg.cpp - PIN callback for smart cards
2 twoaday 225 * Copyright (C) 2003, 2004, 2005, 2006 Timo Schulz
3 werner 36 *
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 "wptW32API.h"
28     #include "wptTypes.h"
29     #include "wptGPG.h"
30     #include "wptCommonCtl.h"
31     #include "wptCard.h"
32     #include "wptUTF8.h"
33    
34    
35     /* Dialog procedure to reuqest the PIN from the user. */
36     BOOL CALLBACK
37     pin_cb_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
38     {
39 twoaday 225 static pin_cb_ctx_s *pin;
40     const char *s;
41 werner 36 int n, len;
42    
43     switch (msg) {
44     case WM_INITDIALOG:
45     pin = (struct pin_cb_ctx_s *)lparam;
46     if (!pin)
47     BUG (0);
48     if (pin->info_text)
49     s = pin->info_text;
50     else
51     s = _("Please enter the PIN");
52 twoaday 225 CheckDlgButton (dlg, IDC_PIN_HIDE, BST_CHECKED);
53 werner 36 SetDlgItemText (dlg, IDC_PIN_HIDE, _("&Hide Typing"));
54 twoaday 105 SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
55 twoaday 225 SetDlgItemText (dlg, IDOK, _("&OK"));
56 werner 36 SetDlgItemText (dlg, IDC_PIN_INFO, s);
57     center_window (dlg, NULL);
58 twoaday 225 SetFocus (GetDlgItem (dlg, IDC_PIN_VALUE));
59 werner 36 SetForegroundWindow (dlg);
60     return FALSE;
61    
62     case WM_COMMAND:
63     if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_PIN_HIDE) {
64     HWND hwnd = GetDlgItem (dlg, IDC_PIN_VALUE);
65 twoaday 225 int hide = IsDlgButtonChecked (dlg, IDC_PIN_HIDE);
66    
67 werner 36 SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0);
68     SetFocus (hwnd);
69     }
70 twoaday 225 switch (LOWORD (wparam)) {
71 werner 36 case IDOK:
72 twoaday 225 n = SendDlgItemMessage (dlg, IDC_PIN_VALUE, WM_GETTEXTLENGTH, 0, 0);
73     if (!n) {
74     msg_box (dlg, _("Please enter a PIN."), _("PIN"), MB_ERR);
75 werner 36 return FALSE;
76     }
77     if (!pin->which || pin->which == CARD_ADMIN_PIN) {
78     sfree_if_alloc (pin->apin);
79     pin->apin = new char[n+2];
80     if (!pin->apin)
81     BUG (0);
82 twoaday 225 len = GetDlgItemText (dlg, IDC_PIN_VALUE, pin->apin, n+1);
83 werner 36 if (len < 8) {
84     msg_box (dlg, _("'Admin PIN' must be at least 8 characters long."),
85     _("PIN"), MB_ERR);
86     sfree_if_alloc (pin->apin);
87     return TRUE;
88     }
89     if (is_8bit_string (pin->apin)) {
90     msg_box (dlg, _("PIN's are currently limited to US-ASCII"),
91     _("PIN"), MB_ERR);
92     sfree_if_alloc (pin->apin);
93     return TRUE;
94     }
95     }
96     else if( pin->which == CARD_USER_PIN) {
97     sfree_if_alloc (pin->upin);
98     pin->upin = new char[n+2];
99     if (!pin->upin)
100 twoaday 225 BUG (NULL);
101     len = GetDlgItemText (dlg, IDC_PIN_VALUE, pin->upin, n+1);
102 werner 36 if (len < 6) {
103     msg_box( dlg, _("'User PIN' must be at least 6 characters long."),
104     _("PIN"), MB_ERR );
105     sfree_if_alloc (pin->upin);
106     return TRUE;
107     }
108     if (is_8bit_string (pin->upin)) {
109     msg_box (dlg, _("PIN's are currently limited to US-ASCII"),
110     _("PIN"), MB_ERR);
111     sfree_if_alloc (pin->upin);
112     return TRUE;
113     }
114     }
115     EndDialog (dlg, TRUE);
116     break;
117    
118     case IDCANCEL:
119     pin->apin = NULL;
120     pin->upin = NULL;
121     EndDialog (dlg, FALSE);
122     break;
123     }
124     break;
125     }
126     return FALSE;
127     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26