CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
The flatfile blues...

 



patk
Deleted

Aug 28, 2000, 2:46 PM

Post #1 of 3 (400 views)
The flatfile blues... Can't Post

I have a got a strange problem.
The following script works but
it only reads the first line
of passwords.txt.

The contents of passwords.txt:
user&&pass
meme&pazz


#!/bin/perl
$username="user";
$password="pass";
open(CUR,"passwords.txt");
while(<CUR> ) {
chop;
@users = split(/\n/);
foreach $line (@users) {
($user, $pass) = split(/&&/, $line);
if($user eq "$username" && $pass eq "$password") {
&login;
$done=1; } } }
close(CUR);
if (!$done) {
print "Content-type:text/html\n\n";
print "error";
exit; }
sub login {
print "Content-type:text/html\n\n";
print "login";
exit; }


I know this is a simplistic script but thats what Im going for. Ive tried using
chomp($line); and chop($line);
and nothing and it still wont read all the database? If the login is user and pass it works (thats the first combination of username/password in passwords.txt) what can I do so it will read the entire database?


Wiliam
Novice

Aug 29, 2000, 3:50 AM

Post #2 of 3 (400 views)
Re: The flatfile blues... [In reply to] Can't Post

Try this snippet of code:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


open (DB,"passwords.txt");
@lines = <DB>;
close DB;

foreach $line (@lines) {
chomp ($line);
($user_name,$password) = split(/\&/,$line);

# Insert your if statment in here.

}
</pre><HR></BLOCKQUOTE>

Rgds,

Wil.

[This message has been edited by Wiliam (edited 08-29-2000).]


rGeoffrey
User / Moderator

Aug 29, 2000, 12:41 PM

Post #3 of 3 (400 views)
Re: The flatfile blues... [In reply to] Can't Post

Your split is on /&&/ and the first line in the password file has a double ampersand. But the second line only has one. Could that be the problem?

On a side note. It might be a good idea to use crypt to store the password into the file. Then if someone gets the password file you are not in as much trouble.
http://www.perlguru.com/perldocs/pod/perlfunc/crypt.html


[This message has been edited by rGeoffrey (edited 08-29-2000).]

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives