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 564555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:46:44+00:00 2026-05-13T12:46:44+00:00

I was hoping someone could help me with a question I’ve come up on.

  • 0

I was hoping someone could help me with a question I’ve come up on.

I have a Session object that handles storage of general session data, I also have a Authentication object which validates a users credentials.

Initially I passed the desired Authentication class name to my Session object then had a login method that created an instance of the Authentication object and validate the credentials. I stored the result of this validation in a Session variable and made it available via a getter. The user data was also stored in the Session for later use. In addition to all this, I have a logout method, which removes the user data from the Session and thus logging the user out.

My question is what role should the Session object play in users logging into their account?

And what other ways might one suggest I go about handling user login, as it stands right now I feel as though I’m getting too much wrapped up in my Session object.

  • 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-05-13T12:46:45+00:00Added an answer on May 13, 2026 at 12:46 pm

    Simply calling your authenticate method should trigger logic within Auth to store the proper data in the session (or some other data store) and Auth should also be used exclusively to retreive/revoke this info. So using the example form your comment it might be:

    class Auth {
      public static function authenticate($identity, $pass)
      {
         // do lookup to match identity/pass if its good then
    
         /* assume $auth is an array with the username/email or 
            whatever data you need to store as part of authentication */
         Session::set('auth', $auth);
         return true;
    
         // if auth failed then 
         Session::set('auth', array('user'=>'anonymous'));
         return false;
      }
    
      public function isAuthenticated()
      {
         $auth = Session::get('auth');
         if(!$auth)
         {
           return false;
         }
    
         return (isset($auth['user']) && $auth['user'] !== 'anonymous'); 
       }
    }
    

    […] as it stands right now I feel as
    though I’m getting too much wrapped up
    in my Session object.

    And id agree. Idelaly for authentication/credentials you shoudl only be interacting with the Auth/Acl object(s). They would then utilize the session as stateful store… but you shouldnt care that its even stored in session. The code utilizng the Auth/Acl object(s) should be completely unaware of this fact.

    For example:

    //Bad
    
    if($session->get('authenticated', 'auth'))
    {
      // do stuff
    }
    
    
    // also bad
    
    if(isset($_SESSION['authenticated']))
    {
      // do stuff
    }
    
    
    //Good
    
    if($auth->isAuthenticated())
    {
      // do stuff
    }
    
    // inside $auth class it might look like this
    public function isAuthenticated()
    {
      $store = $this->getSotrage(); // assume this returns the $_SESSION['auth']
      return isset($store['authenticated']);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an interesting problem that I was hoping someone could help to shed
I have 2 questions that I was hoping someone could help me with. Is
I've come across 2 confusing problems in SML and was hoping someone could help
I'm really hoping that someone can help. I have tomorrow to get this right
I was hoping someone could help me in resolving this issue. I have 3
I was hoping you could help answer an Objective-C based question for me that
I was hoping someone could help me with the following script: jQuery(document).ready(function($) { $(.infoBoxBtn
I was hoping someone could help me with submitting the answers to an HTML
I was hoping someone could help me with a little issue I'm having trouble
Im starting to understand how Magento Event Observers work and hoping someone could help

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.