Do you know where your variables are? | |
PerlMonks |
Re: How to make a secure websiteby redhotpenguin (Deacon) |
on Jul 09, 2004 at 16:12 UTC ( [id://373186]=note: print w/replies, xml ) | Need Help?? |
Have you looked at Apache::AuthCookie?
It takes care of authentication and authorization for you. You create a session key which is passed as the value of the cookie sent to the user, once the user has been authenticated. This key links to a server side copy of the key which is associated with the user's name. Every request a new cookie is created. This is called 'ticket based authentication' and is generally accepted as a best practice for authentication and cookie handling.
No critical information is kept in the cookie itself - just a link to a server side file which contains the username, remote IP, hostname, and whatever else you need to determine the user is actually who they say they are. Usage is relatively simple, you need to subclass 2 methods and configure access in httpd.conf: in your httpd.conf <Location /protected> AuthType My::Apache::AuthCookieHandler AuthName MyProtectedArea PerlAuthenHandler My::Apache::AuthCookieHandler->authenticate PerlAuthzHandler My::Apache::AuthCookieHandler->authorize require valid-user PerlHandler My::Apache::PerlHandler </Location> in My::Apache::AuthCookieHandler sub authen_cred ($$\@) { # Authenticates the user and returns a key my $self = shift; my $r = shift; my @cred = @_; my $user = My::User->new; return unless $user->auth(@cred); my $session_key = My::MD5->new(My::RandomData); # session_key is something like 'lkj125825yk523' _save_to_disk({$session_key => $user}); return $session_key; } sub authen_ses_key ($$$) { # See if there is a user associated with this key my ($self, $r, $session_key) = @_; my $username = _get_from_disk($session_key); $username->valid ? return $username : return; }
In Section
Seekers of Perl Wisdom
|
|