neilwatson has asked for the wisdom of the Perl Monks concerning the following question:
Calling the module:package Mapps::Auth; use Digest::SHA1; use DBI; use warnings; use strict; sub new { my $self = {}; bless $self; return $self; } sub auth { my ($uname, $passwd, $dbsecret, $salt); $uname = shift; $passwd = shift; my $dbh = DBI->connect('dbi:mysql:mapps', 'mapps', 'somepasswd'); # get secret from db my $statement="SELECT auname, passwd, salt FROM admin_users, secrets WHERE users.auid=secrets.auid AND auname='$uname';"; my $sth = $dbh->prepare($statement) or die "Couldn't prepare state +ment: $dbh->errstr"; $sth->execute or die "Couldn't execute statement: $dbh->errstr"; while (my $ref = $sth->fetchrow_hashref){ $dbsecret = $ref->{'passwd'}; $salt = $ref->{'salt'}; } # encrypts password using # SHA-1 algorithm my $sha1 = Digest::SHA1->new; # reset algorithm $sha1->hexdigest; # encrypt my $secret = Digest::SHA1::sha1_hex($passwd . $salt); # does generated secret match database secret? if ($secret eq $dbsecret){ my $auth = 1; return $auth; # no match }else{ my $auth = 0; return $auth; } } 1;
use Mapps::Auth; $auth = new Mapps::Auth->auth($uname, $passwd); if ($auth == 1){ my $s = Mapps::Session->new(); my $id = Apache::Session::Generate::MD5::generate(); $s->new_session($id); my $sid = $s->sid(); # show session from Jeremy's test script printf("SID %s\n", $s->sid()); printf("UID %s\n", $s->uid()); $s->param('foo','123 456'); $s->param(bar =>' baz'); $s->update_session($s->sid()); undef($s); my $x = Mapps::Session->new(); $x->load_session($sid); my @keys = $x->param(); foreach my $key (@keys) { printf("%s => %s\n", $key, $x->param($key)); } # else no auth }else{ print h2('No authentication'); }
I'm getting the error: Can't locate object method "new" via package "Mapps::Auth"
Can some kind monk please explain the nature of creating modules and using them?
Neil Watson
watson-wilson.ca
edited: Sat Apr 3 21:53:56 2004 by jeffa - corrected title misspelling, added readmore
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Understanding and building modules
by jeffa (Bishop) on Apr 03, 2004 at 20:22 UTC | |
|
Re: Understanding and building modules
by BUU (Prior) on Apr 03, 2004 at 22:04 UTC | |
by jeffa (Bishop) on Apr 03, 2004 at 22:24 UTC | |
|
Re: Undertanding and building modules
by gmpassos (Priest) on Apr 03, 2004 at 20:29 UTC | |
by neilwatson (Priest) on Apr 03, 2004 at 21:24 UTC | |
by peanut (Novice) on Apr 03, 2004 at 22:27 UTC | |
|
Re: Understanding and building modules
by tachyon (Chancellor) on Apr 04, 2004 at 06:34 UTC | |
|
Re: Understanding and building modules
by matija (Priest) on Apr 03, 2004 at 20:28 UTC | |
|
Re: Understanding and building modules
by TStanley (Canon) on Apr 04, 2004 at 05:22 UTC |