Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8487903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:22:56+00:00 2026-06-10T21:22:56+00:00

Here is my authentication logic: sub user_logon { my ($dbh, $cgi, $cache, $logout) =

  • 0

Here is my authentication logic:

sub user_logon {
my ($dbh, $cgi, $cache, $logout) = @_;

#use Log::Log4perl qw(:easy);
#Log::Log4perl->easy_init($DEBUG);

my $session = new CGI::Session("driver:MySQL", $cgi, {Handle=>$dbh});

$session->expires("+3h");
my $auth = new CGI::Session::Auth::DBI({
    CGI             => $cgi,
    Session         => $session,
    IPAuth          => 1,
    DBHandle        => $dbh,
    #Log             => 1,
});

if($logout) {
    $auth->logout();
}
else {
    $auth->authenticate();

    if($auth->loggedIn) {
        my $user = Cherry::Schema::ResultSet::Employee::get_employee($dbh, $cache, { number => $auth->{userid} });

        if (!$user->{active}) {
            return { error => $user->{name} . ' is not an active employee.' };
        }

        $user->{cookie} = $auth->sessionCookie();
        return $user;
    }
    elsif($cgi->param('action') eq 'logon') {
        if($cgi->param('log_username') && $cgi->param('log_username')) {
            return { error => 'Your username and/or password did not match.' };
        }
        elsif(!$cgi->param('log_username') || !$cgi->param('log_username')) {
            return { error => 'Please enter a username and a password.' };
        }
    }
    else {
        return { error => 'You are not logged in' };
    }
}
}

sub handle_authentication {
my ($dbh, $cache, $config, $params, $cgi) = @_;

if(($cgi->param('auth') || '') eq 'super_user') { # for automation
    return;
}

if(($params->{action} || '') eq 'log_off') {
    user_logon($dbh, $cgi, $cache, 1); # 1 means log out
    login_form($config, 'Successfully logged out', $params->{login_url}, $params->{title});
}

my $user = user_logon($dbh, $cgi, $cache);

if(exists $user->{error}) {
    login_form($config, $user->{error}, $params->{login_url}, $params->{title});
}
elsif($user->{number}) {
    return $user;
}

}

Then in my code, every time I print a header, it looks something like this:

my $user = Cherry::Authentication::handle_authentication(
$dbh,
$cache,
\%config,
{
    action      => $FORM{action},
    username   => $FORM{log_username},
    password    => $FORM{log_password},
    auth        => $FORM{auth}
},
$cgi
);
print header( 
    -type   => 'application/json',
    -cookie => $user->{cookie}
);

The problem is that this code seems to work very well about 80% of the time. The other 20%, users are getting kicked out (and not after being stale for 3 hours).

Are there any obvious flaws in this code? Have I left any crucial code out?

If you feel is there not enough information here to give a viable solution, do you have any general suggestions on what can be done to troubleshoot these types of issues?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:22:57+00:00Added an answer on June 10, 2026 at 9:22 pm

    With this particular problem, there was some code in play that I was unaware of.

    $cookie = CGI::Cookie->new(
        -name       => $session->name, # problem line
        -value      => $session->id,   # problem line
        -expires    => '+1y',
        -path       => '/',
        -secure     => 0,
    );
    
    my @header = (
        -cookie => $cookie,
        -type => 'text/html',
        -status     => $status
    );
    
    print $cgi->header( @header );
    

    The lines with the comments #problem line were assigning a new session even when one already existed.

    I installed Fiddler HTTP Debugger on the user’s computer that seemed to have the issue the most. Then, once the user was unexpectedly logged out, I reviewed the logs. I was able to find a correlation between the user visiting one url, and the unexpected log out on the next request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Like here: Automatic authentication for Android WiFi Direct I want to create a mobile
Going through the microsoft authentication tutorial listed here they have you create a master
A server and respective client support client authentication but as noted here: SSLHandshakeException: no
Here is the web.config; <?xml version=1.0 encoding=UTF-8?> <configuration> <system.web> <customErrors mode=Off> </customErrors> <authentication mode=Forms>
Should I write authentication logic in my forms for handling user login? For example,
I'm using an ActionFilterAttribute to do custom authentication logic. The Attribute will only be
Am failry new to authentication logic, would anyone be able to tell me if
How could I encapsulate the authentication logic, the URL and the label of a
I’m trying to set up a pretty basic authentication logic flow with the FB
I have followed the article here http://chrisdail.com/2008/08/13/http-basic-authentication-with-apache-cxf-revisited/ I now have a working interceptor for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.