# ODP::Passport::Key - Key handling part of ODP::Password (Version 0.01) # Copyright (C)2002 Richard P. Fuller # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA package ODP::Passport::Key; use strict; use Digest::MD5 qw (md5_hex); # new - Initialises a new ODP::Passport::Key object # Parameters: user, passphrase, issuetime, privs # Returns: ODP::Passport::Key object sub new () { my $object = {}; $object->{'user'} = $_[1]; $object->{'secret'} = $_[2]; $object->{'issued'} = $_[3]; $object->{'privs'} = $_[4]; if ($object->{'privs'}) { $object->{'privs'} =~ s/ +/ /; $object->{'privs'} =~ s/^ //; $object->{'privs'} =~ s/ $//; $object->{'privs'} = " $object->{'privs'} "; } return bless $object; } # isvalidkey - Returns true if the supplied key matches the key of the object # Parameters: key to test # Validity of key sub isvalidkey ($) { my $self = shift; return ($_[0] eq $self->_key()); } # _key - Calculates the key of the object # Parameters: none # Returns: key sub _key () { my $self = shift; my $string; $string = $self->{'user'}.'.'.$self->{'secret'}.'.'.$self->{'issued'}.'.'.$self->{'privs'}; return md5_hex($string); } 1;