Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

sub change_pass { $pass = crypt($q->param('old'), r); if($q->param('old') ne $q->param('reold')) { inerror("Your old passwords don't match"); } elsif($pass ne $user{'pass'}) { print "$pass<br>$user{'pass'}"; inerror("Your old passwords don't match current password"); } else { $newpass = crypt($q->param('new'), r); print "Your password has been chaged"; } }
In this section
elsif($pass ne $user{'pass'}) { print "$pass<br>$user{'pass'}"; inerror("Your old passwords don't match current password"); }
For some reason if the password do match it gives me that error, I really dont see whats wrong. I even checked with...
print "$pass<br>$user{'pass'}";
...and they were the same.

Replies are listed 'Best First'.
Re: elsif ne loop
by Zaxo (Archbishop) on Jun 26, 2002 at 04:13 UTC

    From `man 3 crypt:

    "salt  is  a  two-character string chosen from the set [a-zA-Z0-9./]."
    
    You will be greatly helped debugging this by use diagnostics; and use strict;. Your code appears to be based either on all global variables, or else you have a closure with probably unintended effects.

    All those global-looking things make this impossible to debug in isolation. The whole script needs to be debugged as a unit. It would be a good idea to pass the CGI object and other data to it as parameters.

    After Compline,
    Zaxo

Re: elsif ne loop
by graff (Chancellor) on Jun 26, 2002 at 04:14 UTC

    A couple minor points: (1) please use indentation in your code; (2) isn't it customary to request a user to enter their new password twice, to confirm it, rather than entering the old password twice? (Maybe requesting the old one twice is not a bad idea, but you really should ask for the new one to be typed twice, so the user is assured that the fingers did not slip.)

    update: Removed a lot of incorrect and misguided stuff, after seeing Zaxo's remarks and checking man pages myself. Note that you should read both the section-3 man page Zaxo cited and "perldoc -f crypt", which even gives some examples of proper usage.

Re: elsif ne loop
by bronto (Priest) on Jun 26, 2002 at 07:50 UTC

    Throwing your code on us with really a few explainations and an unexplicative subject is not the best way to ask for help, in my humble opinion.

    For this reason, all I can tell you is: just check perldoc -f crypt. All your crypts are wrong. And use strict! I would also suggest to reask better. Thanks.

    Ciao!
    --bronto

    # Another Perl edition of a song:
    # The End, by The Beatles
    END {
      $you->take($love) eq $you->made($love) ;
    }

Re: elsif ne loop
by screamingeagle (Curate) on Jun 26, 2002 at 04:55 UTC
    i would suggest restricting the scope of the "pass" variable like this :
    my $pass = crypt($q->param('old'), r);
    this will ensure that every time the "change_pass" subroutine is called, the "pass" variable will be re-initialized...