Set author to the node automatically whenever the new user registered and also automatically authenticate the user I have a Drupal site with content type people. In that content type I have a field that contains an email id.

What I want to do is, whenever the new user is registered, I want to compare the user's email with the email field of all the nodes with people as the content type. If these 2 fields match, then set the user as the author of that node.

I don't know how to execute this process.

Can anyone give me a solution?
Create a custom module and  Use below logic hope it will work.

function hook_user_insert(&amp;$edit, $account, $category) {
  $email = $account-&gt;email;
  $uid = $account-&gt;uid;

  $query = db_select('field_email', 'e');
  $query-&gt;addField('e', 'entity_id');
  $query-&gt;condition('e.field_email_data', $email, '=');
  $nids = $query-&gt;execute();

  foreach($nids as $nid){

    //Update node user
    $node = node_load($nid); // ...where $nid is the node id
    $node-&gt;uid    = $uid;
    node_save($node);

   //Add role to user 
   $role_name = 'member';
   if ($role = user_role_load_by_name($role_name)) {
     user_multiple_role_edit(array($uid), 'add_role', $role-&gt;rid);
   }

  }

}