如何在cmd文件中的窗口中隐藏密码字符

时间:2014-02-05 06:24:40

标签: windows command-prompt

我正在尝试处理以下密码输入但我看到密码字符会在Windows上显示,这会破坏产品的安全性。

set username=
set password=
set/p username=Please enter weblogic admin server username:
set/p password=Please enter weblogic admin server password:

请建议任何干净利落的方式。

2 个答案:

答案 0 :(得分: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::::::::::::::

答案 1 :(得分:0)

您需要某种Visual Basic Stuff的帮助

检查此完整Tutorial

@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