Store password in .EXE

I want to implement password protection for a program I wrote. I do not want to use an external file to store the password. Is it possible to store it as part of an EXE, and if so, how do I do it.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I Think this is what you need


The problem with Exes is that you can
not write to them while they are running.

I used this Method in my program to password protection.
procedure TfrmMain.FormCreate(Sender: TObject);
  PCount     : Word;
  MyPassword : String;
  For PCount := 1 To ParamCount Do
    Case PCount of
      1 : Username := ParamStr(PCount);
      2 : MyPassword := ParamStr(PCount);
  if MyPassword <> 'Mypasword' then
    MessageDlg('You can't use this Program', mtError, [mbOk], 0);

first Parameter is User Name, Second Paramater is my password.
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Do you want this passord to be changeable?

if not then try using a resource file, you can compile them into the exe, without the exe giving the password
the alternative it to hard code it and use an app like AsPak to pack and encrypt it.
you could also consider a simple encrypted registry value, held under an inconspicuous name.

if you do want it changeable then I think you're out of luck, I don't think it's possible.
Well, you can not write to an exe file while it is running, there is a trick to run allong this....

You make the main .EXE, and a second .EXE, which can only be started by the main .EXE, and will be after the user changed his password.

When the user changes it's password, the main .EXE stores it in the secondary .EXE, and sets a flag to start the secondary .EXE when the main .EXE quits. After quitting the main .EXE, the secondary .EXE get launched, read its password, and attach this to the main .EXE, and also quits. No need for GUI, just a simple dos or dos-like program can do this, in a split second. So the user will not kown or confronted with odd screens/messages.

So, the secondary .EXE has one job only, and that is to attach passwords to the main .EXE .  By starting the secondary .EXE with parameters, you can avoid users directly starting the secondary .EXE. When a user delete's the secondary .EXE, he/she still can use the main .EXE, but not longer change the password.

It is not that difficult, it's only that Windows locks a file while in use.

Another way could be:
When a .EXE file execute's, it make a copy of itself and that copy can be altered. After quitting, the copy will replace the original. Problem might be....copying while in use (i know that there are tricks herefore too...)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.