Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Is there a module to set a password-protect per node for anonymous users? I'd like to protect some nodes to show it only to those who have the password, without having to create a user account. I've found one for Drupal 6 it has a 7 version but it doesn't have any non-dev releases. And there's another one for Drupal 7 but this one requires the user to register and paste the password to their user profile which is not what I need.

share|improve this question
add comment

3 Answers 3

up vote 4 down vote accepted

The best module for doing this in Drupal 7 is: Protected Pages:

https://drupal.org/project/protected_pages

It allows setting a password per path.

share|improve this answer
add comment

I was able to get the protected_node 7.x-1.x-dev release to work, in this case password-protecting single nodes of type Basic Page, after some debugging and making 11 (yes, eleven) code changes. I found that the password entered when editing the node content was being double-encrypted due to a duplicate call to hook_node_update, and a quick solution was to remove the 11 calls to sha1(), disabling password encryption. The pros and cons of doing this are infinitely debatable, but it was an efficient way to meet both the need and a deadline. This buys some time until further debugging can be done, and hopefully it will help others.

share|improve this answer
add comment

I've also tried the protected_node module for a similar project and haven't been able to get the 7.x development release to work as expected which is unfortunate since I haven't found another module that offers the same functionality -- most of the 'password protection' solutions are focused on protecting files, not individual nodes.

To get our project to work, we tried the custom solution suggested here on stackoverflow:

http://stackoverflow.com/questions/13698477/password-protecting-a-page-node-in-drupal-7

function theme_preprocess_node( &$variables )
{
    $allowed_roles = array("administrator", "media");

    global $user;
    if($variables['nid'] == NODEID)
    {
        foreach($user->roles as $role)
        {
            if(in_array($role, $allowed_roles))
                return;
        }
        drupal_goto("user"); //  redirect to login
    }
}

This would work best if you had a limited number of pages you wanted to protect and didn't need an interface to change or add these frequently. Short of that, the next best alternative is to try and push the development of the protected_node module in the issues queue.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.