In certain circumstances it would be nice to disable some accounts to change their own password (think group accounts).
I did not see any way of doing (I might be wrong) and thought it was a easy modification to this module to support and given the module name appropriate as well.
for your consideration
cheers
------------------------------------------------------------------------
<?php
// $Id: restrict_password_change.module,v 1.1 2008/11/06 02:32:53 jrglasgow Exp $
// by James Glasgow - Tribute Media - http://www.tributemedia.com
/**
* Implementation of hook_perm()
*/
function restrict_password_change_perm() {
return array('change other users password', 'change own password');
}
/**
* Implementation of hook_form_alter()
*/
function restrict_password_change_form_alter(&$form, $form_state, $form_id) {
global $user;
switch ($form_id) {
case 'user_profile_form':
//drupal_set_message('$form =
'. print_r($form, TRUE) .'
');
// check to see if the form is for the current user or if they have permission
if(($user->uid != $form['_account']['#value']->uid) && !user_access('change other users password')) {
// password cannot be changed
$form['account']['pass']['#access'] = FALSE;
// e-mail address cannot be changed
$form['account']['mail']['#access'] = FALSE;
// they cannot be deleted
$form['delete']['#access'] = FALSE;
} else if(($user->uid == $form['_account']['#value']->uid) && !user_access('change own password')) {
// password cannot be changed
$form['account']['pass']['#access'] = FALSE;
// they cannot be deleted
$form['delete']['#access'] = FALSE;
}
}
}
Comments
Comment #1
jrglasgow commentedI have just commit this change
Comment #3
nerdoc commentedah - maybe I'm wrong - but I am using version 6.x-1.2 - and this bug is NOT fixed there. the .module file does NOT contain this code.
is this a regression? Was it forgotten to merge?
Or am I wrong somehow?
Christian
Comment #4
jrglasgow commentedhmm, I don't know what happened, I will have to look into it
Comment #5
wOOge commentedHere is a slight modification of @droetker's code and the latest 1.4 code. For your review and inclusion:
I changed it so that by default you *can* change passwords and you have to explicitly set the *inability* to change them.
Comment #6
Anonymous (not verified) commentedHello friend...There is a problem in my drupal installation. The option to change the password is not being shown. How to enable password change. Please help. Thank you...
Comment #7
wOOge commentedAre you using this module? Can you provide more information?
Comment #8
Anonymous (not verified) commentedYeah, I have installed the module, but I don't know how to configure, I mean, What all permissions should be given to authenticated users?
In a normal Drupal installation, in the 'edit' section of 'My Accounts' page, there will be space for entering the 'new password' twice, but, it is not shown in my Drupal installation at http://blogonity.com now. I don't know, when this problem started. I don't know whether there is any error in /admin/user/settings .
Will I be able to correct it using this module?
Comment #9
wOOge commentedCheck your permissions page first — also make sure you are logged in as the admin user (uid 1).
If that's not it, I would also clear the caches (admin/settings/performance), then disable all of the contrib modules you have installed, and and re-enable the modules one by one to find out if one of your currently installed modules has removed the password fields on you.
Comment #10
Anonymous (not verified) commentedThe propblem was with Gigya socialize...hen i uninstalled it, the website works like a charm. Thank you for your suggestion
Comment #11
Anonymous (not verified) commented