Q&A for How to Add a Password to a .Bat File

Return to Full Article

Search
Add New Question
  • Question
    What if I did not add .bat at the end of codes?
    Sunbakedcow
    Community Answer
    It would save as a .txt file.
  • Question
    This is a nice idea. However, nothing prevents a user from editing the file and seeing the clear text password. What can be done to prevent that?
    Community Answer
    Hide the password .bat file. Attrib it +s +h. And then call it from another, single line .bat, file. That would make it a bit more difficult to edit.
  • Question
    OF the bat file is opened by using Notepad, it will show the code right?
    Community Answer
    Yes. This method only does the real batch code if the correct password is entered. Basically, this method only password protects running the program.
  • Question
    How do I make it secure, as I can look inside of it and find the password?
    Arrogance
    Top Answerer
    Batch files were never intended to be secure, and it's a fool's errand to try. The proper way to store passwords is in a hash. You then run the user's input through the same hashing tool, and if the result is the same, then you proceed. If not, you return an error. The only tool Windows has built-in (in Windows 7, 8, and 10) that can be put to this sort of use is certutil. First, put the password you want to use in a file ( echo password1234 > password.txt ). Then get the hash of the file ( certutil -hashfile password.txt > hashfile.txt ). When the user attempts to enter a password, you do the same thing, redirect their password to a file, get the hash and store it. Then compare the files.
Ask a Question

      Return to Full Article