Hack Forums
[Shell] [Batch] [Source Code] Password protect batch file without storing password plaintext - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] [Batch] [Source Code] Password protect batch file without storing password plaintext (/showthread.php?tid=6294902)



[Batch] [Source Code] Password protect batch file without storing password plaintext - Robert Rouge - Mar 23, 2025

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


RE: [Batch] [Source Code] Password protect batch file without storing password plaintext - DramaKing - Mar 23, 2025

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.


RE: [Batch] [Source Code] Password protect batch file without storing password plaintext - Robert Rouge - Mar 23, 2025

(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


RE: [Batch] [Source Code] Password protect batch file without storing password plaintext - cote - Mar 26, 2025

(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


RE: [Batch] [Source Code] Password protect batch file without storing password plaintext - Anonynuk - Sep 24, 2026

This is interesting to say the least. Thanks for the share!