批处理文件登录

时间:2014-05-07 14:44:05

标签: batch-file cmd

我正在创建一个批处理文件(login.cmd),它从注册文件(signup.cmd)调用登录变量;但我不知道该怎么做。

signup.cmd

::Copyright 2014 Krii.
@echo off
color f0
title Sign Up
echo Welcome,
set /p usern=Choose Username: 
set /p passwd=Choose Password: 
set /p bd=BD mm/dd/yyyy: 
set /p email=Email: 
echo USER >> docs/users.txt
echo ==== >> docs/users.txt
echo Username=%usern% >> docs/users.txt
echo Password=%passwd% >> docs/users.txt
echo BD=%bd% >> docs/users.txt
echo Email=%email% >> docs/users.txt
cls
echo Thank You.
echo.
echo Press any key to Login. . .
pause >nul
start login.bat
exit

login.cmd

::Copyright 2014 Krii.
@echo off
color f0
title Login
echo Please login to continue.
set /p usern=Username:
set /p passwd=Password:

=> => =>

if %usern%==%usern% in signup.cmd && %passwd%==%passwd% in signup.cmd goto authGood
goto authBad

=> => =>

login.cmd中第7行和第8行出错。 我无法弄清楚该怎么做。

请帮助
感谢。

1 个答案:

答案 0 :(得分:2)

in不是命令,而是for命令语法的一部分。

IF没有in

您只需从文件中导入变量:

cd docs
for /f "delims=" %%i in (users.txt) do set %%i

然后获取新变量:

set /p usern=Username:
set /p passwd=Password:

并将旧变量与新变量进行比较:

if %usern%==%Username% if %paswd%==%Password% goto authGood