[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] [分享]批处理判断输入密码错误超过3次之后退出

【问题描述】

谁帮忙看看怎么输入错误3次后才退出,现在是一次直接退出
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

【解决方案】
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set "ScriptPassword=bbs.bathome.net"
  4. set "InputCount=0"
  5. set "InputMax=3"
  6. :GetPassword
  7. set "InputPassword="
  8. set /p "InputPassword=Please input password: "
  9. set /a InputCount+=1
  10. if "!InputPassword!" neq "%ScriptPassword%" (
  11.     if !InputCount! lss %InputMax% (
  12.         goto :GetPassword
  13.     ) else (
  14.         goto :PasswordWrong
  15.     )
  16. ) else (
  17.     goto :PasswordCorrect
  18. )
  19. :PasswordWrong
  20. echo You tried too many times.
  21. goto :End
  22. :PasswordCorrect
  23. echo Hello World
  24. goto :End
  25. :End
  26. pause
  27. goto :eof
复制代码
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

输入密码显示星号,且限制输错密码的次数:
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set "ScriptPassword=BatHome"
  4. set "InputCount=0"
  5. set "InputMax=3"
  6. set "str=0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
  7. for %%a in (%str%) do (
  8.     set /a n+=1
  9.     set ".!n!=%%a"
  10. )
  11. :PasswordLength
  12. set StrLen=0
  13. for /f "skip=1 delims=:" %%a in ('^(echo "%ScriptPassword%"^&echo,^)^|findstr /o ".*"') do (
  14.     set /a StrLen=%%a-5
  15. )
  16. :GetPassword
  17. cls
  18. set /p =请输入密码:<nul
  19. if defined pwds (
  20.     set /p =%pwds%<nul
  21. )
  22. if "%m%" equ "%StrLen%" (
  23.     echo,
  24.     goto :VerifyPassword
  25. )
  26. choice /n /cs /c %str: =%
  27. set "pwds=%pwds%*"
  28. set "pwd=%pwd%!.%errorlevel%!"
  29. set /a m+=1
  30. goto :GetPassword
  31. :VerifyPassword
  32. set /a InputCount+=1
  33. if "!pwd!" neq "%ScriptPassword%" (
  34.     if !InputCount! lss %InputMax% (
  35.         echo 密码错误
  36.         pause
  37.         set "m=0"
  38.         set "pwds="
  39.         goto :GetPassword
  40.     ) else (
  41.         goto :PasswordWrong
  42.     )
  43. ) else (
  44.     goto :PasswordCorrect
  45. )
  46. :PasswordWrong
  47. echo 输错密码次错过多
  48. goto :End
  49. :PasswordCorrect
  50. echo 密码正确
  51. goto :End
  52. :End
  53. pause
  54. goto :eof
复制代码
扩展阅读:批处理输入密码但显示星号
http://bbs.bathome.net/thread-2130-1-1.html
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

返回列表