devxlogo

Application Design and Passwords

Question:
How do you protect an application with a password and store it in the application’s exe-file?

Answer:
You’d have to hard code the password in. Then in the FormCreate method of your main form, you’d do something like this:

procedure TForm1.FormCreate(Sender: TObject);var  pwrd : String;  PassOK : Boolean;begin  Counter := 1;  PassOK := False;  while (Counter < 4) do begin    InputQuery('Type in a password',               'You have ' + IntToStr(4 - Counter) + ' tries left',               pwrd);    if (pwrd = 'MyPassword') then begin      PassOK := True;      Break;    end;      Inc(Counter);  end;  if NOT PassOK then begin    ShowMessage('Exceeded maximum number of tries. ' +                'Press OK to terminate.');    Application.Terminate;  end;end;

This simple password validation gives the user three tries to come up with the correct password. You could be more elaborate by using a resource file with a string resource that is read at run time.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Seasoned Architects Evaluate New Tech

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.