如何在Windows cmd文件中隐藏密码字符

5
我正在尝试处理以下密码输入,但我发现密码字符会在Windows上显示,这破坏了产品的安全性。
set username=
set password=
set/p username=Please enter weblogic admin server username:
set/p password=Please enter weblogic admin server password:

请提供任何干净整洁的方法来完成它。

你知道使用Ctrl+C来停止批处理文件,然后echo "%username%" "%password%"也会破坏你的安全性。 - foxidrive
2个回答

4
这可以让你输入一个隐藏的密码:
::!CARLOS_HIDE_INPUT.BAT
::Code by Carlos on AMBNT 2013-03-10
::Subject: Getkey without Display the input.
::Thread started by jeb
::Note: My edits/additions are not indented 3 spaces


   :::::::::::::BEGIN OF CODE:::::::::::::   
   @Echo Off   
   :HInput
   ::Version 3.0     
   SetLocal DisableDelayedExpansion
Echo Enter your password below:
   Set "Line="
   Rem Save 0x08 character in BS variable
   For /F %%# In (
   '"Prompt;$H&For %%# in (1) Do Rem"'
   ) Do Set "BS=%%#"

   :HILoop
   Set "Key="
   For /F "delims=" %%# In (
   'Xcopy /L /W "%~f0" "%~f0" 2^>Nul'
   ) Do If Not Defined Key Set "Key=%%#"
   Set "Key=%Key:~-1%"
   SetLocal EnableDelayedExpansion
   If Not Defined Key Goto :HIEnd
   If %BS%==^%Key% (Set /P "=%BS% %BS%" <Nul
   Set "Key="
   If Defined Line Set "Line=!Line:~0,-1!"
   ) Else Set /P "=*" <Nul
   If Not Defined Line (EndLocal &Set "Line=%Key%"
   ) Else For /F delims^=^ eol^= %%# In (
   "!Line!") Do EndLocal &Set "Line=%%#%Key%"
   Goto :HILoop

   :HIEnd
   Echo(
Echo Your password is '!Line!'
   Pause
   Goto :Eof

   ::::::::::::::END OF CODE::::::::::::::

0

你需要一些Visual Basic的帮助。

查看这个完整的教程

@echo off & setlocal enableextensions
  :: Build a Visual Basic Script
  set vbs_=%temp%\tmp$$$.vbs
  set skip=
  findstr "'%skip%VBS" "%~f0" > "%vbs_%"
  ::
  :: Prompting without linefeed as in Item #15
  echo.|set /p="Password: "
  :: Run the script with Microsoft Windows Script Host Version 5.6
  for /f "tokens=* delims=" %%a in ('
    cscript //nologo "%vbs_%"') do set MyPass1=%%a
  ::
  echo.
  echo.|set /p="Retype  : "
  for /f "tokens=* delims=" %%a in ('
    cscript //nologo "%vbs_%"') do set MyPass2=%%a
  ::
  :: Clean up
  for %%f in ("%vbs_%") do if exist %%f del %%f
  ::
  :: Demonstrate the result
  echo.
  if "%MyPass1%"=="%MyPass2%" (
    echo The entered password was %MyPass1%
    ) else (
    echo No match)
  endlocal & goto :EOF
  '
  'The Visual Basic Script
  Set WshPass = WScript.CreateObject("ScriptPW.Password") 'VBS
  Password=WshPass.GetPassWord() 'VBS
  WScript.Echo PassWord 'VBS

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接