question of whether authentication of password and username is good

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • poolboi
    New Member
    • Jan 2008
    • 170

    question of whether authentication of password and username is good

    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?
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Should be OK like you have it.

    Don't get into the habit of quoting scalars needlessly:

    Code:
    if ($username eq "$name1" && $password eq "$name2") {
    better written as:

    Code:
    if ($username eq $name1 && $password eq $name2) {
    It is inefficient and can create hard to find bugs.

    Comment

    • poolboi
      New Member
      • Jan 2008
      • 170

      #3
      Originally posted by KevinADC
      Should be OK like you have it.

      Don't get into the habit of quoting scalars needlessly:

      Code:
      if ($username eq "$name1" && $password eq "$name2") {
      better written as:

      Code:
      if ($username eq $name1 && $password eq $name2) {
      It is inefficient and can create hard to find bugs.
      thanks a lot for your help :)

      Comment

      Working...