Reputation:
Im making a log in batch file. that you can log into. its part of my big batch file project... but the problem is when i register and i log in it gives me the error i made in case someone logs in wrong but i know my username and password is right though? can anyone edit my batch file so then it runs smoothly and also explain why you made the changes so i understand what went wrong? heres the code.
@echo off
title LOG IN SCREEN v1.0
color 0a
if EXIST username.uf (
if EXIST password.uf (
goto Login
)) else (goto Reg)
:Reg
cls
echo Welcome to Register!
ping localhost 2 >nul
echo Register to continue
set /p U=Username:
set /p P=Password:
echo %U%>username.uf
echo %P%>password.uf
echo REGISTRATION COMPLETE!
pause
goto Login
:Login
cls
echo Welcome, Please Login to continue
set /p user=Username:
set /p pass=Password:
if %user%==username.uf (
if %pass%==username.uf (
goto welcome
)) else (goto error)
:welcome
cls
echo Welcome to the Test Program!
ping localhost -n 2 >nul
echo Please Exit and come back when you think
echo Program is up!
pause
exit
:error
cls
echo Error. Input Value = Incorrect
echo Error Code = .txt =/ u/p
ping localhost -n 2 >nul
echo Type goback to go back to previous screen
set /p er=
if %er%==goback goto Login
if not %er%==goback goto error
Upvotes: 0
Views: 68
Reputation: 56208
in your :login section you check if %user% is identical to "username.uf" Same with Password
if %user%==username.uf (
if %pass%==username.uf (
goto welcome
)) else (goto error)
Replace this block with:
set /p us=<username.uf
set /p pa=<password.uf
if "%user%"=="%us%" (
if "%pass%"=="%pa%" (
goto welcome
)) else (goto error)
set /p
asks for input, <file.tx
t takes this asked input from a file.
I used "
within the if command, because it would give a syntax error, if one of the variables should be empty
Upvotes: 1