You are here

function protected_node_set_protected in Protected Node 5

Same name and namespace in other branches
  1. 6 protected_node.module \protected_node_set_protected()
  2. 7 protected_node.module \protected_node_set_protected()
  3. 1.0.x protected_node.module \protected_node_set_protected()

Sets the given node to protected with the provided password. The password cannot be empty.

If the node already password protected this method changes the password to the one you provided as $password parameter.

Parameters

int $nid The node ID to set protected or change passsword on.:

string $password The password you wish to set.:

Return value

boolean TRUE if the action was successful, FALSE otherwise.

1 call to protected_node_set_protected()
protected_node_nodeapi in ./protected_node.module
Implementation of hook_nodeapi(). @link http://api.drupal.org/api/function/hook_nodeapi/5

File

./protected_node.module, line 340

Code

function protected_node_set_protected($nid, $password) {
  global $protected_node_salt;
  if (empty($password) || !is_numeric($nid)) {
    return FALSE;
  }
  $success = FALSE;
  if (protected_node_isset_protected($nid)) {
    $success = db_query('UPDATE {protected_nodes} SET passwd = \'%s\' WHERE nid = %d', sha1($protected_node_salt . $password), $nid);
  }
  else {
    $success = db_query('INSERT INTO {protected_nodes} (nid, passwd) VALUES (%d, \'%s\')', $nid, sha1($protected_node_salt . $password));
  }
  return $success !== FALSE;
}