Computing.Net > Forums > Programming > Reading a file using a batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Reading a file using a batch file

Reply to Message Icon

Name: slomifier
Date: March 23, 2008 at 20:13:39 Pacific
OS: XP
CPU/Ram: 512
Comment:

I'm trying to create a batch script that can read a single lined file containing a password (making a login script), than set the read string as a variable. So far, all my attempts have failed. I'm pretty new to batch files, so the simplest script possible would be the best. This is what I've tried so far:

@set tpass=(TYPE "c:\login\%name%s_pass.bat")

This is what I've tried so far, but instead of reading the file and setting it as tpass, it sets tpass as "(TYPE "c:\login\%name%s_pass.bat")".

%name% is the name their trying to login as

tpass is the pass they entered to compare with the stored pass

%name%s_pass.bat is the file I'm trying to read (but It doesn't have to be a bat)



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: March 24, 2008 at 01:47:10 Pacific
Reply:


set /p tpass=< c:\login\%name%s_pass.bat


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: slomifier
Date: March 24, 2008 at 08:06:23 Pacific
Reply:

Having more problems now. I'll copy the main part of my script down:

@:LOGIN
@set /p name=UserName?
@echo Checking...
@ping -n 3 127.0.0.1 >NUL
@if exist c:\login\%name%s_name.bat goto NAMEPASS
@GOTO NAMEFAIL

@:NAMEPASS
@set /p pass=PassWord?
@set /p tpass=< c:\login\%name%s_pass.bat
@if %tpass%==%pass% GOTO LOGINTRUE
@if not %tpass%==%pass% GOTO LOGINFALSE
@pause

(This isn't the entire script, just the part I'm having problems with)

I hope this helps explain what I'm trying to do.

Again, %tpass% is the stored password that is used to compare to the password that they enter at login (%pass%).


0

Response Number 3
Name: Mechanix2Go
Date: March 25, 2008 at 01:11:21 Pacific
Reply:

What is the problem?


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: ghostdog
Date: March 25, 2008 at 06:04:40 Pacific
Reply:

this is certainly not the best way to password authenticate a person. If its for fun, then its ok. If not, set up a proper authentication mechanism, not using batch!


0

Response Number 5
Name: klint
Date: March 25, 2008 at 07:51:04 Pacific
Reply:

I agree with ghostdog. Just to illustrate a point, consider the following user's answer to the first prompt:

UserName? nul type C:\input\* & rem


Then the batch file will execute this statement:

if exist c:\login\nul type C:\input\* & rem s_name.bat goto NAMEPASS

And so this user will get to see everyone's name and password.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Reading a file using a batch file

Simple CRC in a Batch File www.computing.net/answers/programming/simple-crc-in-a-batch-file/14997.html

Newbie creating a batch file www.computing.net/answers/programming/newbie-creating-a-batch-file/16676.html

How to run a batch file on another www.computing.net/answers/programming/how-to-run-a-batch-file-on-another-/15653.html