1
 cls
 @ECHO OFF
 title Folder Secure
 if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
 if NOT EXIST Secure goto MDLOCKER
 :CONFIRM
 echo (Y/N)
 set/p "cho=>"
 if %cho%==Y goto LOCK
 if %cho%==y goto LOCK
 if %cho%==n goto END
 if %cho%==N goto END
 echo Invalid choice.
 goto CONFIRM
 :LOCK
 ren Secure "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
 attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
 echo Folder locked
 goto End
 :UNLOCK
 set/p "variable=>"
 if NOT %variable%== (Here is Enter Your Password) goto FAIL
 attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
 ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Secure
 echo Folder Unlocked successfully
 goto End
 :FAIL
 echo Invalid password
 goto end
 :MDLOCKER
 md Secure
 echo Secure created successfully
 goto End
 :End

Here is my Echo Code, Which is work for to hide the folder with command, y/n and unhide using password. it is work properly there is no mistake in my opinion.

But the problem is that, i need batch file to mask the input text with *.

and I found it on:

batch file to mask input with * without an external file

Here is a way to do it using Powershell in a batch file by Matt Williamson

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=%%pass

After this Wonderful solution which is works Great to mask my text. but After some Modification, i can't understand where to put my Password?

Someone help me!! where do i put my password in Batch file?

Here is the Final Code:

 cls
 @ECHO OFF
 title Folder Secure
 if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
 if NOT EXIST Secure goto MDLOCKER
 :CONFIRM
 echo (Y/N)
 set/p "cho=>"
 if %cho%==Y goto LOCK
 if %cho%==y goto LOCK
 if %cho%==n goto END
 if %cho%==N goto END
 echo Invalid choice.
 goto CONFIRM
 :LOCK
 ren Secure "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
 attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
 echo Folder locked
 goto End
 :UNLOCK

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=%%pass

 if NOT %pass%== folder goto FAIL
 attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
 ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Secure
 echo Folder Unlocked successfully
 goto End
 :FAIL
 echo Invalid password
 goto end
 :MDLOCKER
 md Secure
 echo Secure created successfully
 goto End
 :End

But it is not accepted my password. I don't have a knowledge of Powershell!

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ali Hyder
  • 11
  • 2
  • Change `do set password=%%pass` to `do set pass=%%p` – Mathias R. Jessen Jan 01 '17 at 14:16
  • You do realize that this doesn't provide any security at all, do you? – Ansgar Wiechers Jan 01 '17 at 15:25
  • 3
    @AliHyder Why do you reinvent the wheel? See [What would be the Windows batch equivalent for HTML's input type=“password”?](http://stackoverflow.com/questions/286871/) And see also [Hide Input in Batch File](http://stackoverflow.com/questions/5852759/) and [Can I mask an input text in a bat file?](http://stackoverflow.com/questions/664957/) – Mofi Jan 01 '17 at 17:47
  • Hello i am new, i am sorry. for duplication!! but i search these website before and after!! but i can't understand... – Ali Hyder Jan 03 '17 at 14:42
  • @MathiasR.Jessen it's still not working...can you check my final code completely and save it on your pc, and it's works perfect for you or not? – Ali Hyder Jan 03 '17 at 14:43

1 Answers1

0

You have to use %%p because you are storing it there. Secondly you are not at all providing any security like that. In corresponding Powershell You can use the below code under Powershell section which will help you to encrypt with your own key and you can decrypt it as well.

Instead of:

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=%%pass

Use should do this:

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

Powershell :

The link is having the example where I have used an encrypted password based on AES. You can incorporate the same in your code.

## For the current user , it can encrypt and decrypt as well
$username = "user1@domain.com"
$pwdTxt = Get-Content $SecurePwdFilePath ;
$securePwd = $pwdTxt | ConvertTo-SecureString ;
$credObject = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $securePwd ;
# You can use the $credObject anywhere in your script now.

Hope it Helps you in understanding.

Graham
  • 7,431
  • 18
  • 59
  • 84
Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45
  • @AliHyder : Please accept the answer if it helps you. – Ranadip Dutta Jan 03 '17 at 14:37
  • But it is not working for me :( can you make it for me completely? i know it is not secure, but it is enough for me in my home use only. i am not a big programmer but still a beginner student. and don't have a knowledge of powershell. – Ali Hyder Jan 03 '17 at 14:38
  • @AliHyder: thats why i gave u the logic to set off. At least you try first. Then we are always here to help you out ; – Ranadip Dutta Jan 03 '17 at 14:39
  • when i put P instead of pass, it is not working and nothing do anything, can you check it on you're pc first? – Ali Hyder Jan 03 '17 at 14:41