When user logged in with common shared username and password, I wanted to hide user profile for some of the user based on the given role.

So, I want a feature where user can just logged in and logged out with the given shared user name and password and, I don't want to allow them to change their password or I don't want to allow them to edit in their profile.

I have created separate role for this users.

I came to know that we can hide edit user profile with CSS:

display: none;

Is there any other way to hide user profile based on some roles?

4 Answers 4


You can set access for fields as FALSE as per user roles.

function YOURMODULE_form_user_profile_form_alter(&$form, &$form_state) {
  global $user;
  if(in_array('your_role_name',$user->roles)) {
    $form['account']['pass']['#access'] = FALSE;
    // Similarly other fields, but fields can not be required fields on profile.

a quick method would be to theme the user profile template file and do a quick check for the role there. seeing as you're okay with that css approach, I'm guessing this is more of a nice to have rather than some mission critical thing, so I think this would work nicely for you.



User role field module allows you to specify role-specific fields. When creating a new field, you specify what roles this field is enabled for.

Fields are only visible and editable if a user has a specific role.

This role does not determine access controls for visible fields. You could use the Field Permissions module for setting access controls.

More then 120 sites currently use this module.


Thanks for your help.

I found User Protect module very helpful. It gives the exact same functionality that what I wanted.

We can hide edit account, edit password, email from based on user roles and for specific users too.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.