hsinclai has asked for the wisdom of the Perl Monks concerning the following question:
At this point, to make sure my scalars hold what I think they do, I write a CGI::Carp warn to the log to compare the strings (the brackets are mine), here is the result:# get stored password from pgsql #------------------------------- my $saved_pass = ExternalFunctions::get_word( $dbh, $login_name ); # hash the password given at login time # same function is used at registration time to create the password #------------------------------- my $key = 'KE'; my $eword = ExternalFunctions::create_encrypted( $word, $key ); # Compare the strings #------------------------------- my $passwd_check; $saved_pass eq $eword ? $passwd_check = "good" : $passwd_check = "fail";
saved_pass is: [bd0e9f94ce671b3cdd13081fa5a8b32f9ccd9ebf] .. eword is: [bd0e9f94ce671b3cdd13081fa5a8b32f9ccd9ebf] ..
Other parts of my test app:#!/usr/bin/perl use strict; use warnings; package ExternalFunctions; sub create_encrypted { use Digest::HMAC_SHA1 qw(hmac_sha1 hmac_sha1_hex); my ( $given, $key ) = @_; my $digest = hmac_sha1_hex( $given, $key ); return quotemeta( $digest ); } sub get_word { my ( $dbh, $login_name ) = @_; my $sql_passcheck = qq{ SELECT word FROM residents WHERE lo +gin_name = ? }; my $sth = $dbh->prepare($sql_passcheck); $sth->execute( $login_name ); my ($saved_pass) = $sth->fetchrow_array; $sth->finish(); return $saved_pass; } 1;
apache 1333 on freebsd mod_perl built with perl 5.8.5 firefox Postgresql CGI qw('standard') CGI::Carp qw(fatalsToBrowser) CGI::Session CGI::Cookie HTML::Template DBI Digest::HMAC_SHA1 qw(hmac_sha1 hmac_sha1_hex)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem comparing SHA1 string from db, with hashed login password
by Golo (Friar) on Apr 15, 2005 at 20:55 UTC | |
by hsinclai (Deacon) on Apr 16, 2005 at 03:24 UTC |