-
Notifications
You must be signed in to change notification settings - Fork 0
/
AskPassword.pas
81 lines (69 loc) · 2.32 KB
/
AskPassword.pas
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
unit AskPassword;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, MRC_Helper;
type
TAskPasswordForm = class(TForm)
PasswordEditLabel: TLabel;
PasswordEdit: TEdit;
OkButton: TButton;
UseTCPwdMngrCB: TCheckBox;
class function AskPassword(ParentWindow: HWND; AccountName: WideString; var Password: WideString; var UseTCPwdMngr: Boolean; DisablePWDManagerCB: Boolean = false; HintLabelText: WideString = 'Enter account password:'): integer;
procedure PasswordEditChange(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
private
{Private declarations}
public
{Public declarations}
end;
implementation
{$R *.dfm}
{TAskPasswordForm}
class function TAskPasswordForm.AskPassword(ParentWindow: HWND; AccountName: WideString; var Password: WideString; var UseTCPwdMngr: Boolean; DisablePWDManagerCB: Boolean = false; HintLabelText: WideString = 'Enter account password:'): integer;
var
AskPasswordForm: TAskPasswordForm;
begin
try
AskPasswordForm := TAskPasswordForm.Create(nil);
AskPasswordForm.ParentWindow := ParentWindow;
AskPasswordForm.PasswordEditLabel.Caption := HintLabelText;
AskPasswordForm.Caption := AccountName + ' password';
AskPasswordForm.UseTCPwdMngrCB.Enabled := not DisablePWDManagerCB;
AskPasswordForm.UseTCPwdMngrCB.Checked := UseTCPwdMngr;
result := AskPasswordForm.ShowModal;
if result = mrOk then
begin
Password := AskPasswordForm.PasswordEdit.Text;
UseTCPwdMngr := AskPasswordForm.UseTCPwdMngrCB.Checked;
end;
finally
FreeAndNil(AskPasswordForm);
end;
end;
procedure TAskPasswordForm.FormActivate(Sender: TObject);
begin
CenterWindow(Self.ParentWindow, Self.Handle);
end;
procedure TAskPasswordForm.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
begin
case Key of
VK_ESCAPE:
Close;
VK_RETURN:
if OkButton.Enabled then
OkButton.Click;
end;
end;
end;
procedure TAskPasswordForm.FormShow(Sender: TObject);
begin
(Sender as TAskPasswordForm).PasswordEdit.SetFocus;
end;
procedure TAskPasswordForm.PasswordEditChange(Sender: TObject);
begin
OkButton.Enabled := PasswordEdit.Text <> EmptyWideStr;
end;
end.