i got the code below to authenticate users for database
Expand|Select|Wrap|Line Numbers
- #!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=<STDIN>;
- chop($database);
- print STDOUT "Enter your hostname: ";
- my $hostname=<STDIN>;
- chop($hostname);
- print STDOUT"Enter your username: ";
- my $username=<STDIN>;
- chop($username);
- print STDOUT "Enter your password: ";
- my $password=<STDIN>;
- chop($password);
- $dbh = DBI->connect("DBI:mysql:database=$database;host=$hostname","$username","$password",
- {RaiseError => 1});
- $sth = $dbh ->prepare("SELECT * FROM `user account` WHERE Username='$username'");
- $sth->execute();
- while (my $ref =$sth->fetchrow_hashref()) {
- $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();
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...is it alright?