Tell me more ×
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

1 Answer

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

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.