Force to change password (passsword fields mandatory) for a specific role

Public

Force to change password (passsword fields mandatory) for a specific role

Get raw version
php
  1. function your_module_form_alter(&$form, $form_state, $form_id) {
  2. global $user;
  3.  
  4. if( ($form_id == 'user_profile_form') and (isset($form['account']['pass'])) and (in_array('your role', array_values($user->roles))) ){
  5. $form['account']['pass']['#type'] = 'password';
  6. $form['account']['pass']['#required'] = TRUE;
  7. $form['account']['pass']['#type'] = 'password_confirm';
  8. $form['account']['pass']['#required'] = TRUE;
  9. }
  10. }