We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28524
    • 2 Posts
    Ok, I’m a new to ModX site admin and development posts, so please be gentle ...

    I have thousands of family photographs that I’d prefer to keep private from the world, but provide to authenticated users.  On my old website, I used .htaccess/.htpasswd through basic authentication (e.g. a single login) to restrict access to the subdirectory structure where the files were located.  I can replicate this underneath a subdirectory structure in the new ModX site to a degree, (the root of that structure having its own .htaccess/.htpasswd) but what I end up with are two separate user/password systems, (a sophisticated one with ModX having a nice front-end and back-end admin, and an unsophisticated one handling the basic authentication at the .htaccess/.htpasswd level).  Users have to login twice (once in ModX and once at the Apache authentication level), and whenever a user/password is administrated, the admin (me) needs to administrate the change at both levels as well.  What I’d like, is to combine the login and administration of both -- so when a ModX user/password is administrated -- it writes to the .htpasswd file as well. 

    Has anyone written a patch/bridge to simply make the user administration tasks happen at the .htpasswd level as well?  I’ve scoured the ModX site looking for a way to have passwords which are added/modified to the SQL database to also be written to an .htpasswd file.  Any thoughts?  I was thinking it could be inserted at the most basic write level of the SQL database and not have to alter much code.  More specifically, just adding some basic code to write the user/password to the .htpasswd file right after the successful SQL write is made.  Any thoughts?

    Alternatively, am I missing something here in the way of protecting the photos?  I assume I still need to implement .htaccess/.htpasswd in order to have selective (e.g. authenticated user) access to the raw photos on a file level, right?  (I’m paranoid and not particularly fond of only closing off the directory listing and leaving the files open to read access all the time.)  Please let me know if I’m missing something that ModX already provides as to this function.

    I assume this would be a huge feature for most sites -- being able to implement .htaccess/.htpasswd at a file level.  Anyone have thoughts, help, code?

    Thanks,

    Steve
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I’m pretty sure you can block access to your images except to the page, and of course you can restrict access to the page with the MODx web user management system.

      http://corz.org/serv/tricks/htaccess.php
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 28524
        • 2 Posts
        You bring out a good distinction that the images through .htaccess filters could have different access than the page as configured by the .htaccess page -- but we arrive at the same conclusion that an .htpasswd file must be utilized in conjunction with the .htaccess file to allow only certain users to read the images from the server. If we were to block the images entirely, then the images would not be available to be shown in the pages where they are intended to be shown either, (unless of course you control the access through .htaccess/.htpasswd in combination). We’ve come full circle, since .htpasswd remains essentially a part of the architecture to show the conditionally blocked images, we need to be able to administrate the users/passwords in the .htpasswd file, (which preferably, would be done through ModX and not separately).

        Steve