Page 1 of 1

Save to a log file.

Posted: 09 Apr 2012 13:46
by joakim
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

Re: Save to a log file.

Posted: 09 Apr 2012 18:37
by MrKnowItAllxx
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 :)

Re: Save to a log file.

Posted: 09 Apr 2012 20:09
by Fawers
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.

Re: Save to a log file.

Posted: 13 Apr 2012 12:39
by joakim
TNX this post is now (SOLVED) :!: