We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24393
    • 83 Posts
    rajfantastic Reply #1, 16 years ago
    Good Evening,

    I’m trying to create a user login for revolution that authenticates against an .htpasswd file and then creates a session for a specific context.

    I created a pre-hook for the Login snippet, which I will share once it’s working properly, that authenticates against the password file and returns true if there’s a match.

    My question is how to create a modx user session? I need to use this .htpasswd file instead of storing users in the database.

    Any insight is greatly appreciated!

    Here is the hook I came up with:



    <?php
    	require_once('htpasswd.inc.php'); 
    	// contains the .htpasswd authentication functions
    	
    	$formFields = $hook->getValues();  
    	$user = $formFields['username'];
    	$pass = $formFields['password'];
    
    	if ( authenticate($user, $pass) ) {
    		// create the modx session
    		return true;
    	} else {
    		$errorMsg = 'Authentication failed. Please check your login credentials and try again! ';
    		$hook->addError('user',$errorMsg);  
    		return false;
    	}
    ?>
      stevesunderland.com
      GRAPHICS | INTERACTIVE | MARKETING
      xhtml + ajax + seo websites powered by modx
      • 24393
      • 83 Posts
      rajfantastic Reply #2, 16 years ago
      Let’s try an easier question:

      How can I create a MODx user via the API?

      Many thanks.

      s
        stevesunderland.com
        GRAPHICS | INTERACTIVE | MARKETING
        xhtml + ajax + seo websites powered by modx
        • 32098
        • 31 Posts
        Steve,

        Any joy setting up sessions? I am trying to do just that and failing miserably. I guess you can’t just stick
        session_start();

        at the top of the template for the page, but what do you do?

        I have a form in a sidebar and I am trying to make it sticky so that values are passed from one page to the next wo the user doesn’t have to reenter what they have already entered. A dead end at the moment.
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: webdesig at Jan 04, 2011, 09:15 AM

          Steve,

          Any joy setting up sessions? I am trying to do just that and failing miserably. I guess you can’t just stick
          session_start();

          at the top of the template for the page, but what do you do?

          I have a form in a sidebar and I am trying to make it sticky so that values are passed from one page to the next wo the user doesn’t have to reenter what they have already entered. A dead end at the moment.
          You asked the same question in different words in another thread. Please do not double-post.
            • 32098
            • 31 Posts
            I apologise. When a man is so desperate that he is beginning to eat his laptop, the niceties of forum decorum start to seem less significant than they really are.

            Will try to exert greater self-control next time.