How to prompt/hide a password when opening a CMD?


How to prompt/hide a password when opening a CMD?



I have some code inside a batch file that when I run it my passwords do get hidden. However I am trying to build it so that I can place the code inside any batch file and you will then need to enter the correct password. Currently you can type anything and be allowed access. I know my code isn't written so you have to type something specific in, that is why I am asking here.


@echo off
set "psCommand=powershell -Command "$pword = read-host 'Enter Password' -
AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p
echo %password%



I wish to keep my code as it is because it currently hides what gets typed, but I need someone to add some sort of password checker.





Possible duplicate of Batch File Command Hide Password
– tukan
Jul 3 at 10:30





@tukan No i already have mine hidden i want to make it so you have to enter the correct password using the code i have already written
– connorg98
Jul 3 at 10:46





You do the password checking against what entity? Where is the correct password?
– tukan
Jul 3 at 10:58






if "%password%" neq "MySecretString" goto :eof
– Stephan
Jul 3 at 15:13


if "%password%" neq "MySecretString" goto :eof





Hey @tukan your solve worked thank you very much for showing me to the correct page!
– connorg98
Jul 4 at 8:53




1 Answer
1



Adding the answer based on comments, so this question is answered:



If you use Batch File command hide password have it before your Game code you will have the requested password in your variable.



You can also do a CALL get_password.bat (if you store the batch code and get the return value from that CALL).


CALL get_password.bat


CALL



Thank you Connorg98.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages