[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

password mesage box

With code below i work  with one password.

How should i changeit  to make it work with more passwords?
//// password
procedure tform2.controlpassword();
begin
  ThePassword:=('xyz');  //my  password
  if   richeditWriteOKpassword then
   //  nothing
  else begin
      PostMessage(Handle, InputBoxMessage, 0, 0);
      If InputBox('set editing','Password:','')=(ThePassword)
                Then  begin
     // richedit1.ReadOnly:=false;
      combobox1.Enabled:=true;
      combobox2.Enabled:=true;
      richeditWriteOKpassword:=true;
      richedit1.color:=clwhite;
        end;
    end;
end;
 
// *******************  pasword
procedure TForm2.InputBoxSetPasswordChar(var Msg: TMessage);
var
  hInputForm, hEdit, hButton: HWND;
 begin
  hInputForm := Screen.Forms[0].Handle;
  if (hInputForm <> 0) then
  begin
      hEdit := FindWindowEx(hInputForm, 0, 'TEdit', nil);
               // Change button text:
      hButton := FindWindowEx(hInputForm, 0, 'TButton', nil);
      SendMessage(hButton, WM_SETTEXT, 0, Integer(PChar('Cancel')));
      SendMessage(hEdit, EM_SETPASSWORDCHAR, Ord('*'), 0);
  end;
end;

Open in new window

0
pr2501
Asked:
pr2501
1 Solution
 
Geert GruwezOracle dbaCommented:
use an array
const 
  MaxPasswords = 2;
  Passwords: array[1..MaxPasswords] of string = ('xyz', 'abc');
 
procedure tform2.controlpassword();
var I: Integer;
  aPassword: string;
  Match: Boolean;
begin
  Match := False;
  repeat
    if   richeditWriteOKpassword then
      Match := True
    else 
    begin
      PostMessage(Handle, InputBoxMessage, 0, 0);
      aPassword := InputBox('set editing','Password:','');
      for I := 1 to MaxPasswords do 
        if aPassword = Passwords[I] then 
        begin
          Match := True;
          Break;
        end;
      if Match then 
      begin
        combobox1.Enabled:=true;
        combobox2.Enabled:=true;
        richeditWriteOKpassword:=true;
        richedit1.color:=clwhite;
      end 
      //else ShowMessage('Wrong password');
    end;
  until Match;
end;

Open in new window

0
 
pr2501Author Commented:
thank you
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now