How to allow a role to add users without giving them a password? I have a situation where I would like a specific user role be able to add users without assigning them a password but I can't seem to find a way to do this. Has anyone done this before? I feel like this is something commonly done. Any help would be appreciated. 

Here is the module I have and currently, this code just outputs at the top of the screen for all pages? This is my first module.

Here is my hide_some_fields.module file

function hide_some_fields_form_alter(&amp;$form, $form_state, $form_id) 
{

  global $user;

  if($form_id == 'user_register_form') 
  {                    
    if(in_array('operator', array_values($user-&gt;roles))) 
    { 
      unset($form['account']['pass']);  

    }
  }
}


Here is my .info file as well:

name = Hide Some Fields
description = Hides some fields. The password field when the operator adds patients. 
core = 7.x
People need a password in order to log in to the site. 
Therefore you need to allways insert a password when creating new users.
You can add a default password and set the field as hidden on a specific role but new users will need to know the default password in order to log in. 


function MYMODULE_form_alter(&$form, $form_state, $form_id) {
  global $user;
  if($form_id == 'user_register_form') {

    $default_value = isset($form_state['build_info']['args'][0]['pass'] ? $form_state['build_info']['args'][0]['pass'] : 'DEFAULT PASSWORD';

    if (in_array('YOUR ROLE', array_values($user->roles))) {
      $form['account']['pass']['#default_value'] = $default_value;
      $form['account']['pass']['#access'] = FALSE;
    }
  }
}


EDIT:

Ok I took the time to work this out and therefor I want to adjust my solution:
In order to get this properly working you need to override the full $form['account']['pass'] array. This is because it has the password_confirm type as default, which has the extra confirm field, keeping this type will result in an empty password field on the node submit.
Clive is absolutely right, using a #default_value on a password field results in an error so we need to use the #value. Thas was the unsupported operand types error.
Also, in my first answer I added a condition so see if the form is used to edit a user but now I know that the registration form and edit form are two different forms calling the same user_account_form so we can remove the condition.


function mymodule_form_alter(&amp;$form, $form_state, $form_id) {
  global $user;
  if($form_id == 'user_register_form') {
    if (in_array('USER ROLE', array_values($user->roles))) {
      $form['account']['pass'] = array(
        '#type' => 'password',
        '#size' => 25,
        '#access' => FALSE,
        '#value' => 'DEFAULT PASSWORD',
      );
    }
  }
}

I tested this code and it works like a charm so if you have any problems with it feel free to contact me.