Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Shell 

[Batch] [Source Code] Password protect batch file without storing password plaintext

if look up how to password protect a batch file, they give very not secure code
maybe like:
Code
@echo off
set /p passworld = May I ascertain your password please?:
if %passworld%==notRougeSoftware
(goto correct)
else (goto notcorrect)

here is better security for password storage:
Code
@echo off
:start

::Password protection by RougeSoftware
set "rouge=echo" && set "software=Rouge Password Lock" && set "pString=Enter Password:" set "soft=Your script starts here."
set "rougeSoftware=%rouge% %software%"
%rougeSoftware%
set /p rsPass=%pString%
if not "%rsPass%"=="" (
    %rouge% You entered: %rsPass%
    goto hash
) else (
    %rouge% The string is blank. Please enter a valid string.
    goto start
)
:hash
setlocal
set "tempFile=%temp%\tempString.txt"
%rouge% %rsPass% > "%tempFile%"
for /f "tokens=*" %%i in ('certutil -hashfile "%tempFile%" SHA256 ^| findstr /v "hash" ^| findstr /v "certutil"') do (
set "correctHash=593829e39709f59c49de9418dee55505afa55e5d5c17dede12862f3cf195b62a"
    set "hash=%%i"
)
if "%hash%"=="%correctHash%" (
    %rouge% Correct Password
    pause
    cls && goto YourScriptStart
) else (
    %rouge% Incorrect Password
    pause
    cls && goto start
)

del "%tempFile%"
endlocal

:YourScriptStart
%rouge% %soft%
pause


[ln]
Password: RougeSoftware
Your example is perhaps a best case, but DOS commands do not securely store secrets like PowerShell's SecureString. I would at least remove the command to echo the password, but it probably doesn't matter much. The use case is also questionable because this kind of password protection would be trivial to crack.
(Mar 23, 2025 11:08 AM)DramaKing Wrote:  Your example is perhaps a best case, but DOS commands do not securely store secrets like PowerShell's SecureString. I would at least remove the command to echo the password, but it probably doesn't matter much. The use case is also questionable because this kind of password protection would be trivial to crack.

thank for your interest. Do not know what could use it for, but it is better than what is normal
(Mar 23, 2025 12:35 PM)Robert Rouge Wrote:  thank for your interest. Do not know what could use it for, but it is better than what is normal

I like that. I love there are new snippets of batch code I had no idea about
This is interesting to say the least. Thanks for the share!


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by Robert RougeMar 26, 2025 10:50 PM 1 283 Mar 26, 2025 10:50 PM
Last Post: cote
[Shell] by katerinaxd55Nov 29, 2020 07:47 AM 7 588 Nov 29, 2020 07:47 AM
Last Post: codo3500
[C#] by zxPhantomBladeNov 16, 2020 03:05 AM 4 197 Nov 16, 2020 03:05 AM
Last Post: zxPhantomBlade