LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-27-2006, 01:35 AM   #1
Pratik H Pandya
LQ Newbie
 
Registered: Jun 2005
Location: India
Distribution: RedHat 9.0,Fedora core 3
Posts: 22

Rep: Reputation: 15
Question squid authentication using perl script


hi all,
again one problem.
i tried squid authentication using mysql and in c and i got success,however i want to try it with perl script i.e i want a perl script as my authentication program in squid.conf. that means the following line will be there in squid.conf

auth_param basic program /usr/local/squid/libexec/perl_auth.pl

where perl_auth.pl is my program.

but when i tried this i continuously get the login prompt every time i give username and password.
on command prompt it works fine. i'm not getting it where i'm wrong. i'm also putting simple perl script i've made.
Code:
--------------------------------------------------------------------------------------------------
perl_auth.pl
------------

#!/usr/bin/perl

use CGI;
use DBI;

$dbh = DBI->connect('dbi:mysql:database=mysql_auth','','',{RaiseError=>1});
$user;
$passwd;
while(<>)
{
   chop;
   @F = split;
   $user = $F[0];
   $passwd = $F[1];

   $sql = "select * from data where user='$user' and password='$passwd'";

   $sth = $dbh->prepare($sql);
   $sth->execute();
   @row = $sth->fetchrow_array();
   my $len = @row;
   if($len)
   {
        print "OK\n";
   }
   else
   {
        print "ERR\n";
   }
}

-------------------------------------------------------------------------------------------------
plz help me out.
Thank you.
-Pratik H Pandya.
 
Old 10-28-2006, 07:40 AM   #2
Pratik H Pandya
LQ Newbie
 
Registered: Jun 2005
Location: India
Distribution: RedHat 9.0,Fedora core 3
Posts: 22

Original Poster
Rep: Reputation: 15
hello again all.

i tried a lot for the solution using DBI in perl but i'vent got any success so far. as i've read in docs, i've also tried turning off the buffering in perl using "$|=1" but it didnt help me.
then, i changed the database module in perl and now instead using DBI, i'm using "Mysql.pm" module and it is working fine with that.
so now my perl script looks something like this.

Code:
--------------------------------------------------------------------------------------------------
perl_auth.pl
------------
#!/usr/bin/perl
$|=1;
use Mysql;

$DBHOST = "localhost";
$DBNAME = "mysql_auth";
$DBUSER = "root";
$DBPASS = "";

$DB  = Mysql->connect($DBHOST, $DBNAME, $DBUSER, $DBPASS);
$DB->selectdb($DBNAME);

while(<STDIN>)
{

chomp ;
@login = split(/ /);

$user =  $login[0];
$passwd =  $login[1];


$qry= "select * from data where user='$user' and password='$passwd'";

$sth = $DB->query( $qry);

@emps = $sth->fetchrow;

my $len = @emps;
        if($len >1)
        {
                print "OK\n";
        }
        else
        {
                print "ERR\n";

        }
}
Mysql->disconnect($DB);
--------------------------------------------------------------------------------------------------
i hope this information will help others who are having same difficulty as me.
Any advice or suggestions are invited.

-Pratik H Pandya.

Last edited by Pratik H Pandya; 10-28-2006 at 07:43 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Authentication(auto/Net/SMTP/auth.al) in QNX(sendmail uing perl script) kuttylinux Programming 1 09-20-2006 01:58 AM
client authentication passed onto perl script paul_mat Programming 1 02-12-2006 11:47 PM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 11:22 AM
Need Help With My Perl/cgi Authentication Script dutch357 Programming 0 04-11-2003 10:54 AM
Including methods from a perl script into another perl script gene_gEnie Programming 3 01-31-2002 06:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 01:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration