unit PasswordEdit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, TntStdCtrls;
type
TPasswordEdit =
class(TTntCustomEdit)
private
FXorKey: Integer;
procedure SetXorKey(XorKey: Integer);
procedure SetText(NewText: WideString);
function GetRealText: WideString;
protected
procedure EvKeyPress(
var M: tMessage);
message WM_CHAR;
public
constructor create(AOwner: TComponent);
override;
destructor destroy;
override;
published
property PasswordChar;
property Visible;
property Font;
property CharCase;
property AutoSelect;
property AutoSize;
property OEMConvert;
property Hint;
property ShowHint;
property Tag;
property Text;
property Password: WideString
read GetRealText
write SetText;
{ Set default pass, and read from this property }
property Width;
property Height;
property XorKey: Integer
read FxorKey
write SetXorKey;
end;
procedure Register;
implementation
procedure BurnString(St:
string);
var
count: integer;
begin
for count := 1
to length(st)
do
st[count] := '
';
end;
constructor TPasswordEdit.create(AOwner: TComponent);
begin
inherited Create(AOwner);
PasswordChar := #8226;
Password := '
';
Text := '
';
XorKey := 16;
end;
destructor TPasswordEdit.destroy;
begin
inherited destroy;
end;
procedure TPasswordEdit.SetXorKey(XorKey: Integer);
var
I: Integer;
Str: WideString;
begin
if XorKey <> FXorKey
then
begin
Str := Text;
for I := 1
to Length(Str)
do
Str[I] := WideChar(Ord(Str[I])
xor FXorKey);
FXorKey := XorKey;
for I := 1
to Length(Str)
do
Str[I] := WideChar(Ord(Str[I])
xor FXorKey);
end;
end;
procedure TPasswordEdit.SetText(NewText: WideString);
var
I: Integer;
Str: WideString;
begin
Str := NewText;
for I := 1
to Length(Str)
do
Str[I] := Widechar(Ord(Str[I])
xor FXorKey);
Text := Str;
end;
procedure TPasswordEdit.EvKeyPress(
var M: tMessage);
begin
if not (m.Wparam
in [$08, $0D, $0A, $1B, $09])
then
m.Wparam := m.Wparam
xor FXorKey;
inherited;
end;
function TPasswordEdit.GetRealText: Widestring;
var
I: Integer;
Str: WideString;
begin
Str := Text;
for I := 1
to Length(Str)
do
Str[I] := WideChar(Ord(Str[I])
xor FXorKey);
Result := Str;
BurnString(str);
end;
end.