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: Beginner:
How can i read one line of input from a text file

 



Gwidion
Deleted

Jan 23, 2001, 1:46 AM

Post #1 of 5 (277 views)
How can i read one line of input from a text file Can't Post

I have a problem with my program. It's fine when you have one user in the data base but if you add more it doesn't work. I want to get it to read the first line of the data base then check to see if that is the right user name and password, i want it to keep going like that untill it finds the right combo. Can any one point me in the right direction please?

the password file has teh user names and passwords like this: username|password

#!/usr/bin/perl

#URL to be sent to
$url = "http://www.spam.com";

#Get password list
open(PASS, "issy.pwd") or die "cant open password file\n";
$passlist = <PASS>;
close(PASS);


read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$temp);
foreach $item(@pairs)
{
($key,$content)=split(/=/,$item,2);
$content=~tr/+/ /;
$content=~s/%(..)/pack("c",hex($1))/ge;
$fields{$key}=$content;
}


$user = $fields{user};
$pass = $fields{password};

#joining to make user|pass
$passcheck = join("|", "$user", "$pass");


#Checking user name adn password.

if ($passcheck =~ /$passlist/) {
print "Content-type: text/html\n\n";
print "<html><head><META HTTP-EQUIV=\"REFRESH\" CONTENT=\"0;URL=$url\"></head></html>\n";
}else{
print "Content-type: text/html\n\n";
print qq|
<html>
<head>
<tiltle>Error</title>
</head>
<STYLE>

</STYLE>
</HEAD>
<BODY BGCOLOR=000000 TEXT=9966CC LINK=9966CC VLINK=9966CC>
<h4>Wrong user name or password</h4>
</body>
</html>
|;
}






kencl
User

Jan 23, 2001, 2:30 AM

Post #2 of 5 (275 views)
Re: How can i read one line of input from a text file [In reply to] Can't Post

change $passlist = <PASS>; to @passlist = <PASS>;
and replace if ($passcheck =~ /$passlist/) { with if (grep { $_ eq $passcheck} @passlist) {

There's an article on grep in the Learning Center.

One thing to keep in mind if you allow users to choose their own passwords. They will choose stupid ones like "mother" or "home" or "computer"..., allowing anyone to hack in. Once you read up on dictionary attacks you'll generate their passords for them and they won't be less than 15 characters IMHO.

Hope this is a step in the right direction anyway.

>> If you can't control it, improve it, incorporate it or distribute it with PERL, it doesn't exist!

(This post was edited by kencl on Jan 23, 2001, 5:58 AM)


Gwidion
Deleted

Jan 23, 2001, 11:06 PM

Post #3 of 5 (256 views)
Re: How can i read one line of input from a text file [In reply to] Can't Post

Thanks i read the article, i also looked it up in a book. I think i have worked out where i can use it in another program i wrote.

The passwords are all letters and numbers from 0-9 pluss spaces and unscores, they have to be 5 characters long or longer and are validated by me .. i'll keep in mind what you said though thanks =o)

one other question .. when i was looking for a way to find one line i found this "ne" what does it do?

it was used like this

$wordcount = 0;
$line = <STDIN>
while ($line ne " ') {
chop ($line);
@words = split(/ +/, $line);
$wordcount += @words;
$line = <STDIN>;
}
print ("Total number of words: $wordcount\n");

I want to know what it does and where you would use it .

thank you.

what does IMHO stand for?



kencl
User

Jan 24, 2001, 12:40 AM

Post #4 of 5 (254 views)
Re: How can i read one line of input from a text file [In reply to] Can't Post

ne is a string comparison, while != is a numerical comparison.

IMHO is just In My Humble Opinion :)

If you can't control it, improve it, incorporate it or distribute it with PERL, it doesn't exist!


Gwidion
Deleted

Jan 24, 2001, 2:17 AM

Post #5 of 5 (246 views)
Re: How can i read one line of input from a text file [In reply to] Can't Post

ahaa i remember that now. Its been so long since i read my book. Thanks for helping me.


 
 


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

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