• 0

User Name and Password in Batch File

  • 0

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

echo it works

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.


1 Answer

  1. 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.


    • 0