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:
multiple user/pass's in a file...

 



ultimategamer2k
User

Apr 20, 2001, 1:41 PM

Post #1 of 3 (285 views)
multiple user/pass's in a file... Can't Post

okay, i have a file set up like this
user:pass:user:pass:user:pass:user.... etc
what would be the code if i wanted to have something like this

if (($user eq $users) && ($pass eq $passes)){
do something;}
else { do something else;}

so i want to be able to take each and every user from that file, and match it with what evers inputted through the form, and same with the pass...
... this probably doesnt make much sense, so ask if you need clarification

-------------------------------------------------------------
visit my web site at <a href=http://ultimategamer.cjb.net>here</a>


wickedxter
User

Apr 20, 2001, 8:37 PM

Post #2 of 3 (284 views)
Re: multiple user/pass's in a file... [In reply to] Can't Post

sub check
{
$username = $_[0];
$password = $_[1];

open(FILE,"/path/to/file");
@data = <FILE>;
close(FILE);
foreach $line (@data){
($user, $pass) = split(/\|/,$line);
if(($username eq "$user") && ($password eq "$pass")){
$flag = 1;
}
else {
$flag =0;
}
}
}

call it like
&check("$FORM{'username'}","$FORM{'password'}");
if($flag eq "1"){
#do something
}
else {
print "Error: Wrong Password and Username";
}



zanardi
journeyman

Apr 21, 2001, 9:46 PM

Post #3 of 3 (275 views)
Re: multiple user/pass's in a file... [In reply to] Can't Post

uh bad idea

if your file looks like this:


Code
user name:password:user name:password:user name:password:user name:password:user name:password

your going to run into serious problems, 1 you either put a different user on each line, or 2 you put something inbetween each user account so you can split up the users, then check there name/password

ok, now I suggest you do something like this:


Code
user name:password 
user name:password
user name:password

anyway, this is my version of wicked's code:


Code
check($FORM{'username'},$FORM{'password'}); 

if ($flag) {
print 'yay';
} else {
print 'Error: Wrong Password and Username';
}

sub check {
my ($username,$password) = @_;

open(F,'/path/') or die $!;
@data = <F>;
close F;

$flag = 0;
foreach (@data){
chomp $_;
($user,$pass) = split(/:/,$_);

if (($username eq $user) && ($password eq $pass)) {
$flag = 1;
}
}
}

----------------------
Fueled By ZCom

 
 


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

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