Need to think about how to redo the fields properly.

There should be a password field for nodes, which has the checkbox for whether to show the value in the node. Then for each realm it would have the password. For permitted users they will be able to change the password on a node.

There would also need to be a password field for users, which is where the user stores passwords against their account.

Comments

danielb’s picture

Status: Active » Closed (won't fix)

This is a good idea, but I just don't have time to put that much maintenance into this module, considering about 2 people use it.

hugronaphor’s picture

I need so much this functionality to have possibility to set own password per node. May be I will make a patch.

hugronaphor’s picture

As I sad, I implement this functionality 'to have possibility to set own password per node', not the best way but the fastest:
Just need to set $password_status .

/*
 * Implement hook_form_alter().
 * Create custom textfield for password.
 */

function nodeaccess_password_form_alter(&$form, &$form_state, $form_id) {
  // Machine name of added checkbox field.
  $password_status = 'field_pass_status';

  if (isset($form['#node_edit_form']) && isset($form[$password_status])) {

    $form['pass'] = array(
        '#type' => 'fieldset',
        '#title' => t('Node Password'),
        '#weight' => 1,
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
    );

    $pass_status = $form[$password_status];
    hide($form[$password_status]);
    $form['pass'][$password_status] = $pass_status;

    $form['pass']['field_password'] = array(
        '#type' => 'textfield',
        '#title' => t('Password'),
        '#default_value' => _get_node_password($form['nid']['#value']),
    );
  }
}

/*
 * Implement hook_node_presave().
 * Update password from custom altered field.
 */

function nodeaccess_password_node_presave($node) {
  if (isset($node->field_password)) {
    db_update('nodeaccess_password')
            ->fields(array(
                'password' => $node->field_password,
            ))
            ->execute();
  }
}

function _get_node_password($nid) {
  $pass = db_select('nodeaccess_password', 'np')
          ->fields('np', array('password'))
          ->condition('nid', $nid, '=')
          ->execute()
          ->fetch();
  return (isset($pass->password)) ? $pass->password : FALSE;
}