Save to a log file.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
joakim
Posts: 24
Joined: 07 Mar 2012 12:08

Save to a log file.

#1 Post by joakim » 09 Apr 2012 13:46

Hi, i need help with this code. I want it to save the password and the username in the same log. :D



i have tried every thing XD



:Reg
Title Register
Echo REGISTERATION
Echo:
set /p U=Username:
set /p P=Password:
Echo %P%>password.log
Echo %U%>username.log
Echo Registeration Complete!
Echo Press any key
Pause>nul

:Login
cls
setlocal
set User2=
for /f "tokens=*" %%a in ('type username.log 2^>NUL') do set User2=%%a
set Pass2=
for /f "tokens=*" %%a in ('type password.log 2^>NUL') do set Pass2=%%a
:Loginp2
Title Log in
cls
Echo Log in
Echo:
set /p user= Username:
set /p pass= Password:
if /i %user% equ %User2% (
if /i %pass% equ %Pass2% (
goto W
)
) else (goto IC)

:IC
cls
echo The Password/Username was incorrect please try again
Echo:
Echo press any key

MrKnowItAllxx
Posts: 43
Joined: 20 Mar 2012 20:53

Re: Save to a log file.

#2 Post by MrKnowItAllxx » 09 Apr 2012 18:37

I re-wrote your code as the following, it is untested though

With something like this it is easiest to just put a character you know wont be in the password or username (I used ';', you can change if you want) and use it as a delimeter to seperate them, thats basically all I did

also, you didn't need the 'type xxx.log' in the for loop, just xxx.log will work the same


Code: Select all

:Reg
@echo off
Title Register
Echo REGISTERATION
Echo:
set /p U=Username:
set /p P=Password:
Echo %U%;%P%>login.log
Echo Registeration Complete!
Echo Press any key
Pause>nul

:Login
cls
setlocal
set User2=
set Pass2=
for /f "tokens=1,2 delims=;" %%a in (login.log) do set User2=%%a set Pass2=%%b
:Loginp2
Title Log in
cls
Echo Log in
Echo:
set /p user= Username:
set /p pass= Password:
if /i %user% equ %User2% (
if /i %pass% equ %Pass2% (
goto W
)
) else (goto IC)

:IC
cls
echo The Password/Username was incorrect please try again
Echo:
Echo press any key


Hopefully I haven't made any mistakes, but I hope other members will correct me if I have :)

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Save to a log file.

#3 Post by Fawers » 09 Apr 2012 20:09

Your code is fine, MrKnowItAllxx.

There's only somethings I would change.

In section :Login
from

Code: Select all

for /f "tokens=1,2 delims=;" %%a in (login.log) do set User2=%%a set Pass2=%%b

to

Code: Select all

for /f "tokens=1,2 delims=;" %%a in (login.log) do (
  set User2=%%a
  set Pass2=%%b
  )

Because you put 2 commands in the same line without & or &&.

and in :Loginp2
from

Code: Select all

if /i %user% equ %User2% ( 
  if /i %pass% equ %Pass2% (
    goto W
    )
  )

to

Code: Select all

if [%user%] equ [%User2%] ( 
  if [%pass%] equ [%Pass2%] (
    goto W
    )
  )

I use the brackets for better reading of the code; ignore it if you want.
And I removed the /i switches from the IF statement because usernames and passwords usually are case sensitive.

joakim
Posts: 24
Joined: 07 Mar 2012 12:08

Re: Save to a log file.

#4 Post by joakim » 13 Apr 2012 12:39

TNX this post is now (SOLVED) :!:

Post Reply