Computer Hope

Software => Computer programming => Topic started by: Helpmeh on April 19, 2009, 09:17:47 AM

Title: Logging in failing (batch)
Post by: Helpmeh on April 19, 2009, 09:17:47 AM
I am trying to make get a user to log in, to use the batch script, but the login is failing in the second FOR loop...

Here is my code. List.txt is a file with about 30 lines, each different. The first word is a possible username, the second a possible password. No usernames are the same.

Code: [Select]
@echo off
setlocal enabledelayedexpansion
set fname=list.txt
:looplog
set num1=0
set num2=0
echo Enter your username.
set /p usr=Username^:
Echo Enter your password.
set /p pass=Password^:
pause
for /f "delims=" %%z in ('type %fname%') do (
set /a num1+=1
)
echo Lines^: %num1%
pause
for /f "tokens=1-2 delims= " %%a in ('type %fname%') do (
if "%%a"=="%usr" if "%%b"=="%pass%" goto cont
set /a num2+=1
if %num2%==%num1% cls & echo Username and/or password don't match. & goto looplog
)
:cont
echo HI!
pause

For some reason, the second FOR loop is not LOOPING...so it just keeps on going as if it didn't exist...
Title: Re: Logging in failing (batch)
Post by: Geek-9pm on April 19, 2009, 07:43:35 PM


if "%%a"=="%usr" if "%%b"=="%pass%" goto cont
Title: Re: Logging in failing (batch)
Post by: Helpmeh on April 22, 2009, 04:06:21 PM

if "%%a"=="%usr" if "%%b"=="%pass%" goto cont
I did not see that...