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

标签 windows command-prompt

我正在尝试处理以下密码输入,但我看到密码字符显示在窗口上,这破坏了产品的安全方面。

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

请建议任何干净整洁的方法。

最佳答案

这允许您输入隐藏密码:

::!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::::::::::::::

关于windows - 如何在cmd文件中隐藏Windows中的密码字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21570053/

相关文章:

winXP 上的 python 版本

windows - 批处理脚本条件下的 PowerShell 命令

c++ - 如何使用带有 msys 的 mingw 在 Windows 上编译 googletest?

batch-file - 在批处理脚本中发送 Windows key

java - 运行显示输出/解析命令的 .jar 文件

c# - 何时处置图形对象

java - 在 Java 应用程序中使用 NTLM 身份验证

c# - 如何在我自己的控制台应用程序中执行命令提示符命令

c# - 命令提示符如何知道何时等待退出?