#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Chennai, Tamilnadu, India
    Posts
    19
    Rep Power
    0
    Hello

    I am using a login page(html) with username and password. I have stored the different usernames and passwords in a flat file (e.g xyz.txt). i have used tabspace in between username and password. and there will be single username and password in each line. i am getting the value of username and password from the form and comparing it with the flat file. It is not working properly. It says wrong username or password even i had given the correct username and password which was in flat file. I have given the code below. Can anyone help me?
    -----------------------------------------------------------

    #! /usr/bin/perl
    use CGI;
    print"content-type:text/html\n\n";
    my $action = new CGI;
    my $login = $action->param('username');
    my $password = $action->param('password');
    my $file = "address.txt";
    open(INFILE, $file) or die " The file $file could not be found\n";

    while(<INFILE>){
    my $row = $_;
    chomp($row);
    my @currentrow = ();
    @currentrow = split(/\t/, $row);
    $var = crypt("$password", xx);
    if ($login eq $currentrow[0] && $var eq $currentrow[1])
    {
    print $currentrow[0];
    print $currentrow[1];
    print "It is working\n";
    exit;
    }
    else
    {
    print $currentrow[0];
    print $currentrow[1];
    print "You have entered wrong username or password\n";
    exit;
    }
    }
    -----------------------------------------------------------
    Flat file address.txt
    -----------------------------------------------------------
    john john123
    steve steve123
    david davis

    -----------------------------------------------------------

    Thanks in Advance
    Keshav
  2. #2
  3. Ole` Timer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Location
    N.W. Iowa
    Posts
    472
    Rep Power
    14
    In your code you have:
    Code:
    $var = crypt("$password", xx); 
    if ($login eq $currentrow[0] && $var eq $currentrow[1])
    You've encrypted the password they have entered into the form, then you check the encrypted password agaisnt the password in the address.txt file, but from your sample address.txt file, the password is not encryted, so you won't get a match.

    Mickalo

    Thunder Rain Internet Publishing

    Custom Programming & Database development
    Providing Personal/Business
    Internet Solutions that work!
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Chennai, Tamilnadu, India
    Posts
    19
    Rep Power
    0

    reply


    Hello Mr. Micalo
    Thanx for ur immediate response. Its working fine. But it is checking with the first row only. I need to check all the rows. Tell me what to do.

    Thanx
    Keshav
  6. #4
  7. Ole` Timer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Location
    N.W. Iowa
    Posts
    472
    Rep Power
    14
    I would do this a slightly different way:
    =============================================
    $found = undef;
    open(INFILE, $file) or die " The file $file could not be found\n";
    @data = <INFILE>;
    close (INFILE);

    LOOP: foreach $row (@data) {
    chomp $row;
    @currentrow = split(/\t/, $row);
    $var = crypt("$password", xx);
    if ($login eq $currentrow[0] && $var eq $currentrow[1]) {
    $found = 1;
    last LOOP;
    }
    }
    if (defined($found)) {
    print $currentrow[0];
    print $currentrow[1];
    print "It is working\n";
    exit;
    }
    else
    {
    print "You have entered wrong username or password\n";
    print "Login: $login Password: $password\n";
    exit;
    }
    ==============================

    When you need to loop thru a file to check for a specific match such as a username, password,..etc. It usually works better if you don't use while(<FILEHANDER>), use the foreach loop method. Try the code and see if this works for you.

    Thunder Rain Internet Publishing

    Custom Programming & Database development
    Providing Personal/Business
    Internet Solutions that work!
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Chennai, Tamilnadu, India
    Posts
    19
    Rep Power
    0
    Hello Mickalo
    Its working fine.
    Thanks much
    Keshav

IMN logo majestic logo threadwatch logo seochat tools logo