CGI-Authen-Simple

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
    NAME              => 'CGI::Authen::Simple',
    VERSION_FROM      => 'lib/CGI/Authen/Simple.pm', # finds $VERSION
    PREREQ_PM         => {
            'CGI' => 0,
            'CGI::Cookie' => 0,
            'Template' => 0,
    }, # e.g., Module::Name => 1.1
    ($] >= 5.005 ?     ## Add these new keywords supported since 5.005
      (ABSTRACT_FROM  => 'lib/CGI/Authen/Simple.pm', # retrieve abstract from module
       AUTHOR         => 'Shane Allen <opiate@gmail.com>') : ()),
);

README  view on Meta::CPAN

   perl Makefile.PL
   make
   make test
   make install

DEPENDENCIES

This module requires these other modules and libraries:

  CGI
  CGI::Cookie
  Template
  DBI

COPYRIGHT AND LICENSE

This module is released under the same license as Perl itself.

Copyright (C) 2004 Shane Allen <opiate@gmail.com>

lib/CGI/Authen/Simple.pm  view on Meta::CPAN

package CGI::Authen::Simple;

use strict;
use CGI;
use CGI::Cookie;
use Template;

=head1 NAME

CGI::Authen::Simple - Simple cookie-driven unsessioned form-based authentication

=head1 SYNOPSIS

 use CGI::Authen::Simple;

lib/CGI/Authen/Simple.pm  view on Meta::CPAN


=cut

sub logged_in
{
    my $self = shift;
    my $to_return = 1;

    if(!$self->{'logged_in'})
    {
        my (%cookie) = fetch CGI::Cookie;

        foreach ( qw(userid username password) )
        {
            if(!exists($cookie{$_}) || $cookie{$_}->value eq '')
            {
                $to_return = 0;
                last;
            }
        }

lib/CGI/Authen/Simple.pm  view on Meta::CPAN

                ? "$self->{'PASSWORD'} = " . uc($self->{'HASH_FUNC'}) . "(?)"
                : "$self->{'PASSWORD'} = ?";

        my $profile = $self->{'dbh'}->selectrow_hashref('SELECT *' . $ph
                . ' FROM ' . $self->{'TABLE'} . ' WHERE ' 
                . $self->{'USERNAME'} . ' = ? AND ' . $wph,
                undef, $username, $password);

        if($profile)
        {
            my $username_cookie = new CGI::Cookie( -name=> 'username', -value => $profile->{'username'} );
            my $password_cookie = new CGI::Cookie( -name=> 'password', -value => $profile->{'password'} );
            my $userid_cookie   = new CGI::Cookie( -name=> 'userid',   -value => $profile->{'id'}       );

            print qq!Set-Cookie: $username_cookie\nSet-Cookie: $password_cookie\nSet-Cookie: $userid_cookie\n!;
            $self->{'logged_in'} = 1;
            $self->{'profile'} = $profile;
        }
        else
        {
            $vars->{'login_failed'} = 1;
        }
    }

    if(!$self->logged_in)

lib/CGI/Authen/Simple.pm  view on Meta::CPAN

=back

=head1 TODO

 - template / CSS overrides
 - needs to work with any DB software (since it just takes a DBH, maybe use SQL::Abstract to generate a
   cross DB compatible query.

=head1 SEE ALSO

CGI::Cookie, CGI, Template

=head1 AUTHOR

Shane Allen E<lt>opiate@gmail.comE<gt>

=head1 ACKNOWLEDGEMENTS

=over

=item *



( run in 0.458 second using v1.01-cache-2.11-cpan-e9199f4ba4c )