hey guys
i got the code below to authenticate users for database
[CODE=perl]
#!perl\bin\perl
use strict;
use warnings;
use DBI();
my $dbh;
my $sth;
my $name1;
my $name2;
print STDOUT"Select the name of your database: ";
my $database=<STDI N>;
chop($database) ;
print STDOUT "Enter your hostname: ";
my $hostname=<STDI N>;
chop($hostname) ;
print STDOUT"Enter your username: ";
my $username=<STDI N>;
chop($username) ;
print STDOUT "Enter your password: ";
my $password=<STDI N>;
chop($password) ;
$dbh = DBI->connect("DBI:m ysql:database=$ database;host=$ hostname","$use rname","$passwo rd",
{RaiseError => 1});
$sth = $dbh ->prepare("SELEC T * FROM `user account` WHERE Username='$user name'");
$sth->execute();
while (my $ref =$sth->fetchrow_hashr ef()) {
$name1 = $ref->{'Username'} , $name2 = $ref->{'Password'} ;}
print "$name1\n";
if ($username eq "$name1" && $password eq "$name2") {
print "login successful\n";}
else {
print "login unsuccessful\n" ;}
$dbh->disconnect() ;
[/CODE]
u might be wondering why i need to authenticate when SQL itself can authenticate the users and password
i'm doing this as i gonna connect this to a telnet session
i created a database to categorise users according to the type of commands they can type in the telnet sessions later on
so i'm wondering if such a technique of authenfying...i s it alright?
i got the code below to authenticate users for database
[CODE=perl]
#!perl\bin\perl
use strict;
use warnings;
use DBI();
my $dbh;
my $sth;
my $name1;
my $name2;
print STDOUT"Select the name of your database: ";
my $database=<STDI N>;
chop($database) ;
print STDOUT "Enter your hostname: ";
my $hostname=<STDI N>;
chop($hostname) ;
print STDOUT"Enter your username: ";
my $username=<STDI N>;
chop($username) ;
print STDOUT "Enter your password: ";
my $password=<STDI N>;
chop($password) ;
$dbh = DBI->connect("DBI:m ysql:database=$ database;host=$ hostname","$use rname","$passwo rd",
{RaiseError => 1});
$sth = $dbh ->prepare("SELEC T * FROM `user account` WHERE Username='$user name'");
$sth->execute();
while (my $ref =$sth->fetchrow_hashr ef()) {
$name1 = $ref->{'Username'} , $name2 = $ref->{'Password'} ;}
print "$name1\n";
if ($username eq "$name1" && $password eq "$name2") {
print "login successful\n";}
else {
print "login unsuccessful\n" ;}
$dbh->disconnect() ;
[/CODE]
u might be wondering why i need to authenticate when SQL itself can authenticate the users and password
i'm doing this as i gonna connect this to a telnet session
i created a database to categorise users according to the type of commands they can type in the telnet sessions later on
so i'm wondering if such a technique of authenfying...i s it alright?
Comment