Articles

user name and password in batch file

April 10, 2011 at 17:47:15
Specs: Windows XP, 1gb

ok so i wrote this little script up so people would have to put in a username and password

@echo off
title testing authentication
color 0A
echo enter your username
set username=robert (i set the required name here)
set /p username=
echo now enter your password
set password=2550020 (and the required password here)
set /p password=
goto 1
pause

:1
echo it works
pause


i went to test it and i thought it was working when a thought came to mind

so i tested it and when i typed (blahblah) as the username when its supposed to be (robert)
and the password as (superblah) when its supposed to be (2550020)
my problem is that it continues no matter what i put in, is there a way to make it NOT continue if the entered username and password dont match the ones i set.


See More: user name and password in batch file

Report •


#1
April 10, 2011 at 18:23:13

All you are doing is giving a variable a value and then doing nothing with it.

set username=robert (i set the required name here)

giver username the value of robert.

set /p username=

Prompts for the password and password is given whatever the user enters overwriting what was there previously. No comparison is made with anything

You need to assign the user name and password to a different variable then do a comparison between the stored value and the value the users enters.

Stuart


Report •

#2
April 10, 2011 at 18:38:32

No shortage of lost motion in that mess.
==========================================

@echo off & setLocal enableDELAYedeXpansioN

set /p U=user ?
set /p P=pass ?
if !U! equ this if !P! equ that echo OK


=====================================
Life is too important to be taken seriously.

M2


Report •

#3
April 10, 2011 at 19:42:35

mechanix2, how do i put that into my script though? can you post a edited version of my script please?

Report •

Related Solutions

#4
April 11, 2011 at 01:01:49

Try this;

::Batch.bat
@echo off
title testing authentication
color 0A

:MAIN
cls
echo.
echo Enter your username
echo.
set /p "username= > "
if %username%==robert goto PASSWORD
goto ERROR1

:ERROR1
echo.
echo The username was not found, please try again.
echo.
pause
goto MAIN

:PASSWORD
cls
echo.
echo Enter your password
echo.
set /p "password= > "
if %password%==2550020 goto OK
goto ERROR2

:ERROR2
echo.
echo The password is incorrect, please try again.
echo.
pause
goto PASSWORD

:OK
REM Do your thing here..
cls
echo.
echo Welcome %username%,
echo.
pause
exit

And if you dont want to see your password while typing, you should have a look at Editv32.exe

Regards,

Happy is ONE who says I am an OttoMAN.


Report •

#5
April 11, 2011 at 08:05:25

thanks i did some editing to it, it didnt work right off the back, but after i did some editing it worked great. thanks again.

Report •

#6
August 30, 2011 at 06:10:26

is there a way to add multiple users?

Report •

#7
August 30, 2011 at 07:15:30

Ofcourse, just add more "if" lines.

if %username%==shinigami goto OK
if %username%==anothername goto OK

Happy is ONE who says I am an OttoMAN.


Report •

#8
August 30, 2011 at 07:21:36

sorry yeh i did that after typing it... thanks though i adde a few things to it very helpful

Report •

#9
August 30, 2011 at 07:29:00

is ther an easier way to hide the password then EditV or replace with ' * 's

Report •

#10
August 30, 2011 at 16:48:22

Take a look at this:

@ECHO OFF
SET PASSNAME=
SET /P PASSNAME=<USENAME.TXT
:RETRYUSER
CLS
ECHO Please enter a username:
SET USNAME=
SET /P USNAME=
IF %USNAME%==%PASSNAME% GOTO PASSWORD
GOTO RETRYUSER
:PASSWORD
SET PASSCODE=
SET /P PASSCODE=<PASS.TXT
CLS
ECHO Please enter the password for the account:
SET PSCODE=
SET /P PSCODE=
IF %PSCODE%==%PASSCOE% GOTO HOME
GOTO PASSWORD
:HOME
REM <YOUR CODE HERE>

To set the username and password, make 2 text files called "Pass.txt" and "Usename.TXT" in the same folder that the batch file is located in. Then in Usename.txt, type in the required username to get in, and save. Then in Pass.txt, type in the required password to get in, then save.

Just an idea for a slightly more secure way of storing usernames and passwords.

Mouse could not be found. Click OK to continue.
What to do now?


Report •

#11
September 2, 2011 at 05:56:33

thanks but i wanted to hide the pass as it was being typed using only cmd or equiv commands as i want to be able to use on any comp

Report •

#12
September 2, 2011 at 15:51:19

With my skills, I have to say I don't know how to do that. Your best bet is to use the color command to change the screen background color to the same color of the font, which would hide any text on the screen.

Mouse could not be found. Click OK to continue.
What to do now?


Report •

#13
September 4, 2011 at 01:11:01

Since you can not change the background colour to the text colour.

@shinigami,
Editv32.exe is a great tool to hide the password.

"as i want to be able to use on any comp"
Make a batchfile in a directory with the EditV32.exe and copy the directory to another computer.

Regards,

MUs

Happy is ONE who says I am an OttoMAN.


Report •


Ask Question