Reputation: 1
I am writing a batch file program that gets a username and password from the user and checks them by comparing them with two files, username.dat
and password.dat
.
The username is stored in %username%
and password in %password%
. What I'd like to know is, how do I check these variables against the files username.dat and password.dat?
I've tried using this:
echo %username% >U.dat
echo %Password% >P.dat
COMP U.dat Username.dat
But what value to check? I mean in C or C++ we can check for a return value, but what about this COMP
?
Upvotes: 0
Views: 146
Reputation: 130809
Storing a username and password in files seems like a bad idea to me. But assuming you are going to do it any way...
There is no need to echo your variables to temporary files prior to doing a comparison. There are multiple ways to do your comparison more directly. Here is one method. I'm using delayed expansion so that it supports special characters like &
|
etc in the password (or username).
setlocal enableDelayedExpansion
set userPassOK=1
findstr /x /c:"!username!" Username.dat || set "userPassOK="
findstr /x /c:"!password!" Password.dat || set "userPassOK="
if defined userPassOK (echo username and password passed) else echo Invalid username/password
Upvotes: 2