[EMAIL PROTECTED] wrote:
>
> #!/usr/bin/perl -w
> use strict;
It is better to get into the habit of doing
use warnings;
instead of the -w swicth.
> 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";
- There is no need to escape single quotes in a double-quoted string.
- Ending the die string with a newline prevents die from adding program file and
line number information to the output
- You should include the $! variable in the die string to say /why/ the open
failed
- The three-operator form of open is preferred
- Lexical file handles are preferred
open my $inpass, '<', $pwdlst or die "\nERROR: Cannot open file '$pwdlst': $!";
> my $usrlst = "user.txt";
> open( INUSER, $usrlst ) || die "\nERROR: Cannot open file \'$usrlst\'!
> \n";
open my $inuser, '<', $usrlst or die "\nERROR: Cannot open file '$usrlst': $!";
> while ( my $user = <INUSER> ) {
while (my $user = <$inuser>) {
> chomp $user;
> while ( my $pass = <INPASS> ) {
while (my $user = <$inpass>) {
> chomp $pass;
> if ( $pop3->authenticate( $user, $pass ) ) {
> printf "\nPassword is \'%s\' .\n", $pass;
> } else {
> printf "\nTrying %s - %s\n", $user, $pass;
> }
> }
Here is the source of your problem. When you have come to the end of pass.txt,
attempting to read any more from it wil keep returning EOF. You must do one of
the following.
- open the password file inside the loop over user.txt, immediately before the
while loop that reads it
- Use seek to set the read position to the beginning again after the EOF is
reached, like this
seek $inpass, 0, SEEK_SET
(To do this you must add
use Fcntl ':seek';
at the start of your program.
- If your password file is small, you could read it once, at the start of the
program, into an array or hash. Thereafter you would use the in-memory copy of
the data instead of reading from the file.
> }
>
> close(INUSER);
> close(INPASS);
There is no need to close open file handles at the end of the program. If your
program is written well there is never a need to close them.
> # 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.
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/