Board logo

标题: [其他] [已解决]模拟用户注册、登录的批处理一个BUG,有无大佬能够解决,非常感谢,急 [打印本页]

作者: BingjianREMIX    时间: 2023-5-14 18:25     标题: [已解决]模拟用户注册、登录的批处理一个BUG,有无大佬能够解决,非常感谢,急

本帖最后由 BingjianREMIX 于 2023-5-19 23:23 编辑

这是一个bug,他注册的时候注册名为空,密码为空,登录时用户名为空,密码为空也能登录,求解
  1. :login
  2. cd /d %~dp0
  3. title MICRODOS LOGIN ^& REGISTER
  4. setlocal enabledelayedexpansion
  5. if not exist urini.ini call :register
  6. cls
  7. :users2
  8. color 07
  9. cls
  10. echo.
  11. echo -------------------------
  12. echo MICRODOS LOGIN ^& REGISTER
  13. echo -------------------------
  14. echo.
  15. echo 1.Login
  16. echo.
  17. echo 2.register
  18. echo.
  19. set /p a=Enter you choose:
  20. if /i "%a%" equ "2" (
  21. call :register
  22. goto :users2
  23. ) else if "%a%" equ "1" (
  24. set /p str1=Enter the USER NAME:
  25. set /p str2=Enter the password:
  26. findstr /x /c:"USER NAME:!str1! PASSWORD:!str2!" "urini.ini" 1>nul && (
  27. cls
  28. color 27
  29. echo TRUE!
  30. echo Please push any key to continue!
  31. pause>nul
  32. goto :dos
  33. ) || (
  34. cls
  35. color 47
  36. echo ERROR!
  37. echo Please push any key to continue!
  38. pause>nul
  39. goto :users2
  40. )
  41. ) else goto :users2
  42. :register
  43. set /p str1=Enter the new user name:
  44. set /p str2=Enter the new password:
  45. >>"urini.ini" echo USER NAME:%str1% PASSWORD:%str2%
  46. goto :users2
复制代码

作者: terse    时间: 2023-5-14 20:37

那就加给判断吧 判断str1 str2是否为空
作者: Batcher    时间: 2023-5-14 21:49

回复 1# BingjianREMIX
  1. :register
  2. set "str1="
  3. set /p "str1=Enter the new user name:"
  4. if "x%str1%" equ "x" (
  5.     echo Invalid user name.
  6.     goto :register
  7. )
  8. set "str2="
  9. set /p "str2=Enter the new password:"
  10. if "x%str2%" equ "x" (
  11.     echo Invalid password.
  12.     goto :register
  13. )
  14. >>"urini.ini" echo USER NAME:%str1% PASSWORD:%str2%
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2