Recent

Author Topic: How to disable password save.  (Read 6468 times)

toplek

  • Jr. Member
  • **
  • Posts: 53
How to disable password save.
« on: April 30, 2017, 02:19:51 pm »
Hi,

after putting "Edit" on the form with PasswordChar set to special char, the form displays with about 1 second delay. After research I found that reason is in saving password in OS by "ThinkVantage Password Manager".

Is it possible to disable password save ?

br
Piotr Polok

Thaddy

  • Hero Member
  • *****
  • Posts: 14159
  • Probably until I exterminate Putin.
Re: How to disable password save.
« Reply #1 on: April 30, 2017, 02:28:52 pm »
- Exclude it from ThinkVantage.
or
- Simulate the *** yourself instead of relying on the underlying Windows EditBox control. (From which TEdit is derived) The password mode for editbox (Tedit) is an OS control flag that the manager uses to detect passowrds , so simply mimic it with onkeydown Etc.
« Last Edit: April 30, 2017, 03:12:25 pm by Thaddy »
Specialize a type, not a var.

toplek

  • Jr. Member
  • **
  • Posts: 53
Re: How to disable password save.
« Reply #2 on: April 30, 2017, 03:13:21 pm »
Good idea, but It's look like it's not possible this way becouse 'Key := 149; ' on Edit1KeyDown event will not change result.

Could you please give an example.

ASerge

  • Hero Member
  • *****
  • Posts: 2212
Re: How to disable password save.
« Reply #3 on: April 30, 2017, 07:37:37 pm »

sky_khan

  • Guest
Re: How to disable password save.
« Reply #4 on: April 30, 2017, 09:31:12 pm »
I just wrote this. Note that it does not prevent copying its text.

Code: Pascal  [Select][+][-]
  1. unit khnPassEdit;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6. uses
  7.   LCLType, LMessages, Classes, Graphics, Controls, StdCtrls;
  8.  
  9. type
  10.  
  11.   { THiddenPassEdit }
  12.  
  13.   THiddenPassEdit = class(TCustomEdit)
  14.   private
  15.     FCanvas : TControlCanvas;
  16.   protected
  17.     procedure Change;override;
  18.     procedure WMPaint(var Msg: TLMPaint); message LM_PAINT;
  19.     procedure WMKeyDown(var Message: TLMKeyDown); message LM_KEYDOWN;
  20.   public
  21.     constructor Create(aOwner:TComponent);override;
  22.     destructor Destroy;override;
  23.   end;
  24.  
  25. implementation
  26.  
  27. { THiddenPassEdit }
  28.  
  29. procedure THiddenPassEdit.Change;
  30. begin
  31.   inherited Change;
  32.   Repaint;
  33. end;
  34.  
  35. constructor THiddenPassEdit.Create(aOwner: TComponent);
  36. begin
  37.   inherited Create(aOwner);
  38.   ControlStyle:=ControlStyle+[csOpaque];
  39.   FCanvas:=TControlCanvas.Create;
  40. end;
  41.  
  42. destructor THiddenPassEdit.Destroy;
  43. begin
  44.   inherited;
  45.   FCanvas.Free;
  46. end;
  47.  
  48. procedure THiddenPassEdit.WMKeyDown(var Message: TLMKeyDown);
  49. begin
  50.   inherited WMKeyDown(Message);
  51.   Repaint;
  52. end;
  53.  
  54. procedure THiddenPassEdit.WMPaint(var Msg: TLMPaint);
  55. var
  56.   R : TRect;
  57.   W : integer;
  58. begin
  59.   R:=ClientRect;
  60.   FCanvas.Handle:=Msg.DC;
  61.   FCanvas.Brush.Color:=clLtGray;
  62.   FCanvas.Brush.Style:=bsDiagCross;
  63.   W:=FCanvas.TextWidth(Text);
  64.   if W<R.Right then R.Right:=W;
  65.   FCanvas.Rectangle(R);
  66. end;
  67.  
« Last Edit: April 30, 2017, 09:34:12 pm by SkyKhan »

ASerge

  • Hero Member
  • *****
  • Posts: 2212
Re: How to disable password save.
« Reply #5 on: April 30, 2017, 11:36:22 pm »
@SkyKhan what task do you solve? Excluding TEdit control from ThinkVantage?

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1311
    • Lebeau Software
Re: How to disable password save.
« Reply #6 on: May 02, 2017, 01:20:56 am »
@SkyKhan what task do you solve? Excluding TEdit control from ThinkVantage?

The theory is that removing use of the ES_PASSWORDCHAR window style from the Edit control will prevent ThinkVantage from interacting with the Edit control.  But then the asterisks have to be simulated manually.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

toplek

  • Jr. Member
  • **
  • Posts: 53
Re: How to disable password save.
« Reply #7 on: May 04, 2017, 10:17:05 pm »
@SkyKhan Thank you for the answer, custom draw of TEdit control is good idea. There are two problems with this code:

1. After mose click on Edit, the real text is visible.
2. After changing 'FCanvas.Rectangle (R)' to 'FCanvas.TextOut (SpecialChars)', the cursor is positioned at the end of the real text rather than at the end of the drawn special character.

Do you known how to solve above problems ?

toplek

  • Jr. Member
  • **
  • Posts: 53
Re: How to disable password save.
« Reply #8 on: May 04, 2017, 11:21:33 pm »
It looks like, the real problem is in flag 'ES_PASSWORD' in TEdit :

https://msdn.microsoft.com/en-us/library/windows/desktop/bb775464(v=vs.85).aspx

Do you known how to send message to Tedit by 'SendMessage' in order to avoid password save in the system ?

sky_khan

  • Guest
Re: How to disable password save.
« Reply #9 on: May 04, 2017, 11:37:34 pm »
@toplek

Did you try if custom draw password edit control without using ES_PASSWORD flag will solve your problem ?
Because I wrote it as an example assuming password managers will not notice it is a password edit, as Remy said.
If so I think I can fix these two remaining problems or I can try at least.

toplek

  • Jr. Member
  • **
  • Posts: 53
Re: How to disable password save.
« Reply #10 on: May 04, 2017, 11:59:43 pm »
Yes, the custom draw password without using ES_PASSWORD flag is solving the proble, please try to solve two problems with custom drawing ;).

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1311
    • Lebeau Software
Re: How to disable password save.
« Reply #11 on: May 05, 2017, 09:42:15 pm »
It looks like, the real problem is in flag 'ES_PASSWORD' in TEdit :

https://msdn.microsoft.com/en-us/library/windows/desktop/bb775464(v=vs.85).aspx

Do you known how to send message to Tedit by 'SendMessage' in order to avoid password save in the system ?

You can't use SendMessage() because ES_PASSWORD is not a window message.  It is a window style.  You have to use CreateWindow/Ex() and SetWindowLong/Ptr() to manipulate window styles.

Just clear the TEdit.PasswordChar property (set it to #0), that will remove the ES_PASSWORD style.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

sky_khan

  • Guest
Re: How to disable password save.
« Reply #12 on: May 06, 2017, 09:53:24 pm »
Here,
It flickers a bit and I could not find a way to handle highlighting selected text if text is longer than it's width. So I had to limit it with MaxLength otherwise it scrolls and draw highlights at wrong position.
If I could query how much it scrolled I could fix it too but it seems impossible. It is not ideal but maybe you can use it if you can keep character count limit applied. Otherwise I guess only solution is to write an edit control from scratch

Code: Pascal  [Select][+][-]
  1. unit khnPassEdit;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6. uses
  7.   LCLType, LMessages, Classes, SysUtils, Graphics, Controls, StdCtrls, ExtCtrls;
  8.  
  9. type
  10.   { THiddenPassEdit }
  11.  
  12.   THiddenPassEdit = class(TCustomEdit)
  13.   private
  14.     FCanvas : TControlCanvas;
  15.     FPasswordChar: char;
  16.     procedure setPasswordChar(AValue: char);
  17.   protected
  18.     procedure Change;override;
  19.     procedure WMPaint(var Msg: TLMPaint); message LM_PAINT;
  20.     procedure WndProc(var Message: TLMessage); override;
  21.   public
  22.     constructor Create(aOwner:TComponent);override;
  23.     destructor Destroy;override;
  24.   published
  25.     // we cant use real PasswordChar because it will set ES_PASSWORD flag
  26.     property PasswordChar : char read FPasswordChar write setPasswordChar default '*';
  27.   end;
  28.  
  29. implementation
  30. uses
  31.   Windows;
  32.  
  33. { THiddenPassEdit }
  34.  
  35. procedure THiddenPassEdit.setPasswordChar(AValue: char);
  36. begin
  37.   if FPasswordChar=AValue then Exit;
  38.   FPasswordChar:=AValue;
  39.   Invalidate;
  40. end;
  41.  
  42. procedure THiddenPassEdit.Change;
  43. begin
  44.   inherited Change;
  45.   Repaint;
  46. end;
  47.  
  48. constructor THiddenPassEdit.Create(aOwner: TComponent);
  49. begin
  50.   inherited Create(aOwner);
  51.   ControlStyle:=ControlStyle+[csOpaque];
  52.   FCanvas:=TControlCanvas.Create;
  53.   FPasswordChar:='*';
  54.   Font.Name:='Courier New';
  55.   Font.Size:=9;
  56.   Width:=132;
  57.   MaxLength:=16;
  58. end;
  59.  
  60. destructor THiddenPassEdit.Destroy;
  61. begin
  62.   inherited;
  63.   FCanvas.Free;
  64. end;
  65.  
  66. procedure THiddenPassEdit.WMPaint(var Msg: TLMPaint);
  67. var
  68.   I : Integer;
  69.   X : Integer;
  70. begin
  71.   FCanvas.Handle:=Msg.DC;
  72.   FCanvas.Font.Assign(Font);
  73.   X:=1;
  74.   for I:=1 to Length(Text) do
  75.   begin
  76.     if (I>SelStart) and (I<=SelStart+SelLength) then
  77.     begin
  78.       FCanvas.Font.Color:=clHighlightText;
  79.       FCanvas.Brush.Color:=clHighlight;
  80.     end
  81.     else
  82.     begin
  83.       FCanvas.Font.Color:=Font.Color;
  84.       FCanvas.Brush.Color:=clWindow;
  85.     end;
  86.     FCanvas.TextOut(X,1,FPasswordChar);
  87.     X:=X+FCanvas.TextWidth(Text[I]);
  88.   end;
  89.   Msg.Result:=0;
  90. end;
  91.  
  92. procedure THiddenPassEdit.WndProc(var Message: TLMessage);
  93. begin
  94.   inherited WndProc(Message);
  95.   case Message.msg of
  96.     LM_KEYFIRST..LM_KEYLAST,
  97.     LM_LBUTTONDOWN..LM_XBUTTONDBLCLK,
  98.     LM_SETFOCUS,LM_KILLFOCUS:
  99.       Repaint;
  100.   end;
  101. end;
  102.  
  103. end.

toplek

  • Jr. Member
  • **
  • Posts: 53
Re: How to disable password save.
« Reply #13 on: May 15, 2017, 12:15:09 am »
Thenk for you work ;),

it's look like, It's not necessary to handle highlighting selected text, because the text is hidden. I made some minor changes to your code. I also can not solve the problem with flickering.
Code: Pascal  [Select][+][-]
  1. unit khnPassEdit;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6. uses
  7.   LCLType, LMessages, Classes, Graphics, Controls, StdCtrls;
  8.  
  9. type
  10.   { THiddenPassEdit }
  11.  
  12.   THiddenPassEdit = class(TCustomEdit)
  13.   private
  14.     FCanvas : TControlCanvas;
  15.     FPasswordChar: char;
  16.     procedure setPasswordChar(AValue: char);
  17.   protected
  18.     procedure Change;override;
  19.     procedure WMPaint(var Msg: TLMPaint); message LM_PAINT;
  20.     procedure WndProc(var Message: TLMessage); override;
  21.   public
  22.     constructor Create(aOwner:TComponent);override;
  23.     destructor Destroy;override;
  24.   published
  25.     // we cant use real PasswordChar because it will set ES_PASSWORD flag
  26.     property PasswordChar : char read FPasswordChar write setPasswordChar default '*';
  27.   end;
  28.  
  29. implementation
  30.  
  31. { THiddenPassEdit }
  32.  
  33. procedure THiddenPassEdit.setPasswordChar(AValue: char);
  34. begin
  35.   if FPasswordChar=AValue then Exit;
  36.   FPasswordChar:=AValue;
  37.   // Fast repaint.
  38.   Invalidate;
  39. end;
  40.  
  41. procedure THiddenPassEdit.Change;
  42. begin
  43.   inherited Change;
  44.  
  45.   // Fast repaint.
  46.   Invalidate;
  47. end;
  48.  
  49. constructor THiddenPassEdit.Create(aOwner: TComponent);
  50. begin
  51.   inherited Create(aOwner);
  52.   ControlStyle:=ControlStyle+[csOpaque];
  53.   FCanvas:=TControlCanvas.Create;
  54.  
  55.   FPasswordChar:= chr(7); // Dot.
  56.   Font.Name:='Courier New';
  57.   Font.Size:=11;
  58.  
  59.   //AutoSize := False;
  60.   AutoSelect := False;
  61.  
  62.   Width  := 132;
  63. end;
  64.  
  65. destructor THiddenPassEdit.Destroy;
  66. begin
  67.   inherited;
  68.   FCanvas.Free;
  69. end;
  70.  
  71. procedure THiddenPassEdit.WMPaint(var Msg: TLMPaint);
  72. var
  73.   I : Integer;
  74.   X : Integer = 4;
  75.   PasswordCharPxWidth : Integer = 0;
  76. begin
  77.   FCanvas.Font.Assign(Font);
  78.   FCanvas.Handle:=Msg.DC;
  79.  
  80.   SelLength := 0;
  81.  
  82.   if text = '' then
  83.    begin
  84.     FCanvas.Font.Color:= clSilver;
  85.     FCanvas.TextOut(x, 2, 'Enter Password');
  86.    end
  87.   else
  88.   begin
  89.    PasswordCharPxWidth := FCanvas.TextWidth(Text[1]);
  90.  
  91.    for I:=1 to Length(Text) do
  92.     begin
  93.      FCanvas.TextOut(x, 2, FPasswordChar);
  94.      x += PasswordCharPxWidth;
  95.     end;
  96.   end;
  97.  
  98.   Msg.Result:=0;
  99. end;
  100.  
  101. procedure THiddenPassEdit.WndProc(var Message: TLMessage);
  102. begin
  103.   inherited WndProc(Message);
  104.   case Message.msg of
  105.     LM_KEYFIRST..LM_KEYLAST,
  106.     LM_LBUTTONDOWN..LM_XBUTTONDBLCLK,
  107.     LM_SETFOCUS,LM_KILLFOCUS:
  108.     Invalidate;
  109.   end;
  110. end;
  111.  
  112. end.

 

TinyPortal © 2005-2018