Batch file 如何使用循环密码创建批处理文件?

Batch file 如何使用循环密码创建批处理文件?,batch-file,windows-10,Batch File,Windows 10,我想创建一个批处理文件,在每次打开时更改密码。 我用谷歌搜索了一下,但没有结果。 这是我用来设置密码锁的代码 @echo off color a :start echo What is the password? set /p word= : if %word%==what goto right if not %word%==what goto wrong :wrong cls echo The password is wrong. Do you want to try again? set /

我想创建一个批处理文件,在每次打开时更改密码。 我用谷歌搜索了一下,但没有结果。 这是我用来设置密码锁的代码

@echo off
color a
:start
echo What is the password?
set /p word= :
if %word%==what goto right
if not %word%==what goto wrong
:wrong
cls
echo The password is wrong. Do you want to try again?
set /p pass= :
if %pass%==yes goto start
if %pass%==Yes goto start
if %pass%==YES goto start
if %pass%==y goto start
if %pass%==Y goto start
if not %pass%==yes goto end
if not %pass%==Yes goto end
if not %pass%==YES goto end
if not %pass%==y goto end
if not %pass%==Y goto end
:right
cls
echo The password is correct. Are you sure you want to proceed?
pause

我不能100%确定您考虑的密码有多复杂,但您可以在文件中创建预定义单词的列表,我们将其称为
words.txt
单词应采用列表形式:

passw1
guess
pseudo
daniel
susan
europe
etc.
然后创建批处理文件:

@echo off
set /a rd=%random%%%20
for /f "tokens=1,* delims=]" %%a in ('type "words.txt" ^| find /v /n ""') do if [%rd%]==%%a]  echo %%b
pause
所有这些操作都是向每行添加NMBER,如果
random
变量中
0
20
的随机数与任何行号匹配,它将使用该特定单词作为密码。上述示例仅使用了最大值20,但您可以更改:

然后根据您当前的代码。无需测试
yes
的每个大小写变体,因此您几乎可以使用
if/i
进行大小写不敏感匹配的测试,但鉴于您在yes中只对
y
进行大小写测试,因此您可以将当前代码更改为:

@echo off
color a
:start
set /p "word=What is the password?: "
if "%word%"=="what" goto right
:wrong
cls
echo The password is wrong. Do you want to try again?
set /p pass= :
if /i "%pass:~0,1%"=="y" goto start
goto :end
:right
cls
echo The password is correct. Are you sure you want to proceed?
pause
还要注意的是,我们不需要测试
if
if not
,因为如果不满足
if
条件,我们可以直接进入下一个标签

PS!!我不知道你想让别人怎么猜一个随机密码,如果可能会变得相当复杂。

1,试试这个:
if/I“%pass%”==“yes”转到开始
if/I“%pass%”==“y”转到开始
goto:EOF
。2.考虑使用“是”/“否”提示…