I created a module that allows users to set passwords for the node. If the password exists, the node is not loaded unless the password is correct.

The password check is done in the hook_load() function of my node. It checks the $_SESSION variable for the password. If the password is incorrect or empty, it redirects(drupal_goto()) the user to the form that allows the user to insert the password.

I turned on cache on the site and noticed that the "unlocked" node is stored in the cache and served to users without asking for the password. In order to get around this, the $user variable is checked to see if it is an anonymous user and if yes, they are redirected to the user login page with an error message being displayed.

I don't want people to have to register to view password protected content

How do I disable caching for the nodes/pages that are password protected? Is there a function that prevents the cache from being build for the current page?

I tried to search for the caching API or tutorials, but, I didn't find anything.

Thanks,
Michael

Comments

mooffie’s picture

Why don't you crate a special user account and log them in as that user? They don't need to register.

See userswitcher.module.

Michael M’s picture

I didn't think about that. I guess that would be my last resort. I would prefer a way not to cache the current page.

Any other suggestions?

PRZ’s picture

Michael... I am interested in this as well. Did you come up with any solutions?

Michael M’s picture

It seems like it is not easily doable....

When I come up with a solution, I will post it. Currently, I ask users to login to unlock a gallery.

----
http://eUploads.com

WeRockYourWeb.com’s picture

Hi Michael,

Would you mind posting your module? I could use this functionality.

Thx!
Alex

Michael M’s picture

Alex,

Actually, it's not an actual module that locks nodes, but it is a gallery module that has the feature to lock a gallery node.

Michael

----
http://eUploads.com

elio’s picture

HI friends,

I am looking for password locking module, Anything is already out? I would like to extend such a module with the capability of node editing protected by password (let's say who has a password can even edit the node), anybody interested in this?

maulwuff’s picture

definitely!
Did you manage anything in the meantime on this topic?
I tried to modify the password-module, but I am stuck in the authentication part and fairly new to drupal.
See also http://drupal.org/node/212980

hairylunch’s picture

In case anyone else is looking to password protect nodes for anonymous users (in other words, password protect some pages, but not require a user account), I'd suggest trying out the Secure Site module . . .

ressa’s picture

Original posting deleted -- I didn't read the first post before I posted.

slosa’s picture