Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Sicheres Passwort Eingabefeld (https://www.delphipraxis.net/132430-sicheres-passwort-eingabefeld.html)

cookie22 12. Apr 2009 15:21


Sicheres Passwort Eingabefeld
 
Liste der Anhänge anzeigen (Anzahl: 2)
hallo,

bei meiner nach einem halbwegs sicheren password edit bin ich auf folgende kompo gestossen. das funktioniert unter delphi 5 auch alles gut, nur ab delphi 2005 funktioniert die komponete nicht mehr richtig.

wenn ich ein passwort abfrage bekomme ich in delphi 2005 das passwort und das passwort spiegel verkehrt ausgegeben.
wenn also mein Passwort folgendes ist: "Test Passwort" erhalte ich "test passworttrowssaP tseT". Ich hab mal alles zusammen gepackt und angehängt, ein screenshot ist auch dabei. hat jemnd eine ahnung warum das nicht mehr klappt ab bds3?

frohe ostern,
cookie

P.S. Ich poste mal die kompo hier:
Delphi-Quellcode:
unit mx_hookedit;



{ GetMsgProc }
function GetMsgProc(nCode: Integer; wParam, lParam: Integer): LResult; stdcall;
{ process messages:
    WM_KEYUP
      VK_CONTROL
    WM_KEYDOWN
      VK_CONTROL
      VK_BACK
      VK_DELETE
      VK_ENTER
    WM_CHAR
}
const
  VChar = $38;
var
  VMsg     : PMsg;
  VMess    : Cardinal;
  VWndValid : Boolean;
  VStartSel : Integer;
  VEndSel  : Integer;
  VKeyState : TKeyBoardState;
  VVirtKey : Integer;
  VScanCode : Integer;
  VCharCode : array[0..3] of Char;
  VRetVal  : Smallint;
  VKBLayout : HKL;
  S        : string;
begin
  Result := 0;
  //
  if (nCode < 0) then
    Result := CallNextHookEx(FHook_GetMsg, nCode, wParam, lParam)
  else if (nCode = HC_ACTION) then begin
    VMsg := PMsg(Pointer(lParam));
    VWndValid := IsWindow(FHookWnd) and (VMsg.hwnd = FHookWnd);

    if VWndValid and (FSecretLines <> nil) and (FSecretLineID >= 0) and (FSecretLineID < FSecretLines.Count) then begin
      S := FSecretLines[FSecretLineID];
      VMess := VMsg.message;

      case VMess of
        // WM_KEYUP
        WM_KEYUP : begin
          VVirtKey := VMsg.wParam;
          case VVirtKey of
            // VK_CONTROL
            VK_CONTROL : begin
              FCTRLDown := false;
            end;
          end;
        end;
        // WM_KEYDOWN
        WM_KEYDOWN : begin
          GetKeyBoardState(FKeyState);
          //
          VVirtKey := VMsg.wParam;
          case VVirtKey of
            // VK_CONTROL
            VK_CONTROL : begin
              FCTRLDown := true;
            end;
            // VK_BACK
            VK_BACK : begin
              GetStartEndSel(VStartSel, VEndSel);
              Delete(S, VStartSel, VEndSel - VStartSel + 1);
            end;
            // VK_DELETE
            VK_DELETE : begin
              GetStartEndSel(VStartSel, VEndSel);
              if (VEndSel = VStartSel) then Delete(S, VStartSel + 1, VEndSel - VStartSel + 1)
              else                         Delete(S, VStartSel + 1, VEndSel - VStartSel);
            end;
            // VK_RETURN
            VK_RETURN : begin
              GetStartEndSel(VStartSel, VEndSel);
              Delete(S, VStartSel + 1, VEndSel - VStartSel);
            end;
            // VK_...
            else begin
              if not FCTRLDown then begin
                GetKeyBoardState(VKeyState);
                VScanCode := VMsg.lParam and $FF0000;
                //
                ZeroMemory(@VCharCode, SizeOf(VCharCode));
                VKBLayout := GetKeyBoardLayout(GetCurrentThreadID);
                VRetVal := ToASCIIEx(VVirtKey, VScanCode, VKeyState, @VCharCode, 0, VKBLayout);
                //
                if (VRetVal <> 0) then begin
                  GetStartEndSel(VStartSel, VEndSel);
                  Delete(S, VStartSel + 1, VEndSel - VStartSel);
                  Insert(VCharCode, S, VStartSel + 1);
                  //
                  if ProcessStr(S, FSecretTextMaxLength) then begin
                    VKeyState[VK_SHIFT] := 0; SetKeyBoardState(VKeyState);
                    VMsg.wParam := VChar;
                  end
                  else VMsg.wParam := 0
                end;
              end;
            end;
          end;
        end;
        // WM_CHAR
        WM_CHAR : begin
          case VMsg.wParam of
            $09   : S := S + #09;
            $0D  : S := S + #$0D#$0A;
            VChar : VMsg.wParam := Ord(FSecretChar);
          end;
          //
          SetKeyBoardState(FKeyState);
        end;
      end;
      //
      SetSecretLine(FSecretLineID, S);
    end;
  end;
  //
  if (FMX_HookEdit <> nil) and Assigned(FMX_HookEdit.FOnGetMsg) then FMX_HookEdit.FOnGetMsg(nCode, wParam, lParam);
end;
ich vermute den fehler hier irgendwo, in delphi 5 triggert das nur einmal aber delphi 2005 zwei mal. :gruebel:

Luckie 12. Apr 2009 18:14

Re: Sicheres Passwort Eingabefeld
 
Könntest du bitte die 600 Zeilen Code aus deinem Beitrag nehmen? Stört etwas und ausserdem hast du den Code ja im Anhanhg.

Die Muhkuh 12. Apr 2009 18:39

Re: Sicheres Passwort Eingabefeld
 
Stört? Ist doch brav zusammengeklappt.

himitsu 12. Apr 2009 19:15

Re: Sicheres Passwort Eingabefeld
 
Zitat:

Zitat von Die Muhkuh
Stört? Ist doch brav zusammengeklappt.

nicht unbedingt - siehe Code-Folding in den Foren-Optionen
ansonsten vergrößert es die Datenbank unnütz


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:35 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz