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;
}
?>