Hello Monks.
I have a general question about usign CGI::Session for web page authentication.

I have a very simple web application that authenticates users based on a username and password they supply. The form checks this against the SQL db and if OK redirects them to a page. I would like to stop anyone just bypassing this page(s) by putting the direct URL in the browser.

Looking at CGI::Session I can generate a new CGI session id and pass this along via the URL or hidden forms (I need to assume no cookies will be saved/allowed at the client). I am having trouble with the mechanics of what needs to be done but I am thinking of the following: On every page check for the existence of a cgi->param("sessionid") if none exists redirect to the login page. Is this common practice?
The problem I have then is timing out the users session and/or stopping anyone logging in with the same id. (and I suppose someone adding a sessionID to URL). Is it a good idea to, upon successful login, store the sessionid in the MySQL database and then on everypage check the existing sessionid is equal to the latest one in the db and if not kick them out?

Does anyone have any general thoughts, tutorials on this? I have read the CGI::Session, CGI::Session::Tutorial and CGI::Session::Cookbook and the code isn't really the problem, it's more the method I am struggling with.
Sorry for the long winded, generic question!


In reply to CGI Authenticaiton by packetstormer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.