我正在处理受密码保护的记事本样式的东西 更新的代码:
:login
cls
Echo Welcome %Name%
Echo Please enter your password
set/p %passin%=
if "%passin%" neq "%pass%" goto :menu
echo Correct password.
pause
goto :menu
:loginfail
echo incorrect password, you have (%loginfails%) attempts remaining
[INSERT SCRIPT FOR CHANGING THAT NUMBER AND SOME METHOD OF SECURITY WHEN IT HITS ZERO HERE]
pause
cls
goto :login
但是,set/p
之后,即使我输入了正确的密码,该密码也会自动关闭,而我早先在文件中设置了加载脚本。
任何帮助将不胜感激:)
EDIT:输入密码后,它不再关闭,但是无论它认为密码是正确的是什么。我该如何解决(当我有回声时,它说如果“” ==“” goto:menu (
EDIT2:我用neq作为评论者说,结果相反,仍然不起作用
答案 0 :(得分:0)
您遇到的错误(关闭,批处理文件意外终止)是因为您已编写:
set /p %passin%=
这是完全错误的。您必须输入仅变量名(不带百分号(%...%
))。
具有您提供给我们的脚本的正确版本:
@echo off
set "pass=PASS_YOU_WANT"
set "loginfails=NUMBER_YOU_WANT"
set "name=NAME_YOU_WANT"
:login
cls
Echo Welcome %Name%
set /p "passin=Please enter your password: "
if /i NOT "%passin%"=="%pass%" ( goto loginfail ) else ( echo Correct password. )
pause
goto menu
:loginfail
set /a "loginfails-=1" >nul
echo incorrect password, you have (%loginfails%) attempts remaining
rem [INSERT SCRIPT FOR CHANGING THAT NUMBER AND SOME METHOD OF SECURITY WHEN IT HITS ZERO HERE]
pause
cls
goto login
其中if /I
表示启用区分大小写。
希望这会有所帮助!