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

Collegues

Using:

my $username = $self->query->param('username'); my $password = $self->query->param('password'); my @auth = LSRfm::Show->search(name => $username); my $id = pop(@auth); my @aut = LSRfm::Database::Show_Passwords->search(id => $id); my $pass = shift(@aut); # my $output; my $ok = "n/a"; if ($password eq $pass) {$ok = "yes";} else {$ok = "no";} print Data::Dumper->Dump([$username, $password, $id, $pass, $ok]);

I get:

$VAR1 = 'Offline'; $VAR2 = 'password'; $VAR3 = bless( { 'id' => '1' }, 'LSRfm::Show' ); $VAR4 = bless( { 'id' => '1' }, 'LSRfm::Database::Show_Passwords' ); $VAR5 = 'no'; HTTP/1.1 200 OK Date: Mon, 17 Apr 2006 20:48:13 GMT Server: Apache/1.3.29 (Unix) mod_perl/1.29 mod_become/1.3 DAV/1.0.3 PH +P/4.3.9 mod_fastcgi/2.4.2 Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Transfer-Encoding: chunked Content-Type: text/html; charset=ISO-8859-1 1 1 0

The password and username and correct, but $ok validates as false for some reason when it should be tru and thus yes!

Any ideas?

Barry Carlyon barry@barrycarlyon.co.uk

2006-04-20 Retitled by g0n, as per Monastery guidelines
Original title: 'SOLVED!! pops, shifts and eqs'

Replies are listed 'Best First'.
Re: pops, shifts and eqs
by davidrw (Prior) on Apr 17, 2006 at 21:06 UTC
    Well, $pass is an object, and it must not stringify in the $password eq $pass clause. Is there a method like $pass->text or $pass->value you can compare against instead?

    On a side note (and you may very well have done this just for debugging), don't use "yes", "no", and "n/a" for boolean values .. you lose the ability to say if($ok) and you also introduce string comparison and the potential for error/typos/maintenance that that brings..
    my $ok; # it's undef if( ... ){ # going to actually set it $ok = $password eq $pass ? 1 : 0 } ... if($ok){ # do good stuff } ... if(!$ok){ # if failed for any reason } ... if(defined $ok && !$ok){ # if set to false } ... if(! defined $ok){ # if unset } ... printf "Status: %s\n", (defined $ok ? ($ok?'yes':'no') : 'n/a');

      no -> there a method like $pass->text or $pass->value

      I dont know how

      Barry Carlyon barry@barrycarlyon.co.uk

        package LSRfm::DBI; use strict; use warnings; use base qw(Class::DBI); use Apache::Reload; use LSRfm::Config; my $config = $LSRfm::Config::DATABASE; LSRfm::DBI->connection("dbi:mysql:host=$config->{host};database=$confi +g->{name}", $config->{dbuser}, $config->{dbpasswd}); 1;

        Barry Carlyon barry@barrycarlyon.co.uk
Re: pops, shifts and eqs
by m.att (Pilgrim) on Apr 17, 2006 at 21:04 UTC
    In your Data::Dumper output, $pass & $password are not the same. $pass seems to contain an LSRfm::Database::Show_Passwords object and $password contains the string 'password'.

      LSRfm::Database::Show_passwords returns

      id: 1

      password: password

      hence i shift it so it should be object = password i think

      Barry Carlyon barry@barrycarlyon.co.uk
Re: pops, shifts and eqs
by zer (Deacon) on Apr 17, 2006 at 21:02 UTC
    can you provide an example of the database
      package LSRfm::Database::Show_Passwords; use strict; use base qw(LSRfm::DBI); use Apache::Reload; __PACKAGE__->table('show_passwords'); __PACKAGE__->columns(All => qw/id password/); __PACKAGE__->set_sql(all => 'SELECT __ESSENTIAL__ FROM __TABLE__'); 1;

      Barry Carlyon barry@barrycarlyon.co.uk