保护tedit组件的密码

汉斯·哈兹(Hans Harz)

我只是想知道是否存在一种有效的方法来保护带有密码字符集的TEdit字段,而该工具的设置只能以纯文本形式将其读回。

我认为这些工具例如可以抓住TEdit的目标句柄并使用gettext或类似的东西。

到目前为止,我尝试过的工作是为密码创建一个散列,将其存储在变量中,然后将其写回到丢失的TEdit上,但这对我来说没有意义,因为我需要存储另一个密码来计算内部的散列可执行文件。

也许有人对如何使用这些工具保护TEdit文本有更好的主意。

塞塔克·阿奎兹(Sertac Akyuz)

具有ES_PASSWORD样式的编辑控件可防止将其文本复制到剪贴板。剩下的就是拒绝向其他应用程序显示其窗口文本并将密码字符重置为null。后代类可以处理这些。

type
  TPasswordEdit = class(TEdit)
  protected
    procedure EmGetPasswordChar(var Message: TMessage); message EM_GETPASSWORDCHAR;
    procedure EmSetPasswordChar(var Message: TMessage); message EM_SETPASSWORDCHAR;
    procedure WMGetText(var Message: TMessage); message WM_GETTEXT;
  end;

procedure TPasswordEdit.EmGetPasswordChar(var Message: TMessage);
begin
  // for nirsoft's BulletsPassView, probably only prevents further inspection, 
  // injecting a thread perhaps - I have no idea what it's doing..
  if (PasswordChar = #0) or not InSendMessage then
    inherited;
end;

procedure TPasswordEdit.EmSetPasswordChar(var Message: TMessage);
begin
  if (PasswordChar <> #0) and (Message.WParam <> 0) then
    inherited;
end;

procedure TPasswordEdit.WMGetText(var Message: TMessage);
begin
  if (PasswordChar = #0) or not InSendMessage then // allow owning thread
    inherited;
end;

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章