1

I am using darland theme in drupal7 site and I want user to reset their password for the fist time when they login with temporary login credentials given by admin,i,e created user when he login for the first time he should able to see the reset password form and later he can use his account as required,!!how to resolve this issue??can anyone know?

And below screen shot which i have added is my login screen and the code showing up in the right page is cos i have added the code in page.tpl.php to solve above problem explained so now it looks like, however if i take off the code from page.tpl.php it will be removed. enter image description here

enter image description here

7
  • This is the link for reset password /user/pass. By default reset password link is added below the user login block. You can add this link anywhere you want using menu. Sep 11, 2015 at 7:40
  • @SumitMadan: thanks, i got it, but user should login with the password provided by admin after once they login for the first time it should ask to reset there password....just like gmail facility
    – kashish
    Sep 11, 2015 at 9:00
  • @kashish as in your image there is a login link shown. Click on this link, there will you see request new password link under tab.
    – WaQaR Ali
    Sep 11, 2015 at 9:49
  • please can you show up your login form?
    – WaQaR Ali
    Sep 11, 2015 at 9:51
  • waqar Ali: please find the login page attached
    – kashish
    Sep 11, 2015 at 10:03

3 Answers 3

2

Options to set a password

First of all, the very only way for any user to change their password, is using either of these approaches:

  • using /user/xyz/edit (with xyz = uid of the user), where there is an option to change your password. But: this can only be done for a logged in user (which assumes that the user succeeded in entering their (old) password).
  • using a "one time login URL", as further described below.

Requesting a new password

When you are not logged in, you can navigate to /user/password within your site (either for D6 or D7). That is where you will find the "request new password".

For a logged in user, in D7, who navigates to /user/password, you won't get the same "request new password" form however. Instead, you'll get something like so ([email protected] is the eMail Id to where the request new password eMail will be mailed to):

Password reset instructions will be mailed to [email protected]. You must log out to use the password reset link in the e-mail.

eMail a one time login URL

You may also want to look at what is configured as email templates when new users are created (located at admin/config/people/accounts). Such as the template for "a new user created by an administrator". By default (in D7) that template looks like so (bold markup added here):

[user:name],

A site administrator at [site:name] has created an account for you. You may now log in by clicking this link or copying and pasting it to your browser:

[user:one-time-login-url]

This link can only be used once to log in and will lead you to a page where you can set your password.

After setting your password, you will be able to log in at [site:login-url] in the future using:

username: [user:name] password: Your password

So this one time login URL could be used by a new user. And if for some reason that URL doesn't work (anymore), then such user can still user /user/password.

Variation: any user (such as an admin ...) can use that URL and specify the eMail ID of the new user who has to set a new password (the eMail will arrive at the new user ... if the eMail ID is correct).

Redirect on login when using a one-time login URL

One might consider adding links like /user/password and/or /user/xyz/edit (with xyz = uid of the logged in user) anywhere in your site (e.g. somewhere in your theme).

However, I'd use an approach using the Rules module to redirect on login when using a one-time login and password reset. How to actually do so (there are multiple solutions) is detailed in issue # 480584. Personally I'd go for a solution based on what is described in comment #37 of it.

If you're not familiar (enough/yet) with Rules, checkout the 32 (!!!) great, and free, video tutorials Learn the Rules framework, organized in 7 chapters.

Use the Force password change module

Another approach might be to use the Force password change module (available also for D8 now, merci Jaypan!). Here are some details from its project page:

This module allows administrators to force users, by role, individual user, or newly created user, to change their password on their next page load or login, and/or expire their passwords after a period of time.

Features:

  • Ability to force all users in a role to change their password.
  • Ability to force individual users to reset their password from their profile edit page (user/[UID]/edit).
  • Ability to set an expiry on passwords so that if users haven't changed their password within that time period, they will be required to do so.
  • Ability to force all new users to change their password on first-time login (site-wide setting for all new users).
  • Ability for admins to force individual users to change their password on first time login when creating a new user. (Note: If the global setting forcing all new users to reset their password is enabled on the module settings page, this checkbox will not appear as it is redundant).

  • Listing of stats on the user edit page (user/[UID]/edit) showing:

    • Whether the user has a pending forced password change.
    • When the user last had their password forced to be changed.
    • When the user last changed their password.
  • Status page for each role showing:

    • Password change details by user.
    • The last time at which the role was forced to change the password.
    • A form to force the password change for all users in that role.

Use admin/config/people/force_password_change and enable Force password change on first-time login (can also be configured for selected roles).

6
  • 1
    OK, I "finished" my answer ... Curious to hear if you want to consider such "Rules" approach ... Are you familiar with Rules? If not: you don't know what you're missing ... PS: note that I cleaned up (=deleted) my prior comments also (you may want to do the same). Sep 11, 2015 at 10:59
  • pierre Vriens: i am not so familiar with rules m newbie to drupal, well thanks a lot i will try as u have given the solution.):):):):
    – kashish
    Sep 12, 2015 at 4:59
  • Thank you for the feedback for now. I added "some" more recommended tutorials to get you going with "rules". After you had some time to digest / study, you will hopefully not forget to provide some feedback to this (and the other?) answers to your question here. similar to what is written in drupal.stackexchange.com/help/someone-answers ... Sep 12, 2015 at 10:50
  • 1
    Added another option (module) to consider, near the end of my answer ... Sep 12, 2015 at 11:25
  • I just voted it up - partially because I'm the creator of the Force Password Change module that you wrote about in the post. It was made for this exact type of situation. I just recently ported it to D8, with a full set of tests, so the D8 version is the most stable one yet.
    – Jaypan
    Jan 22, 2017 at 1:32
0

Check it to putting in theme file

function YOURTHEMENAME_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'user_pass':
        print '<pre>';print_r($form); print '</pre>';
      break; 
  }
}
2
  • adi:theme in which file...?m using danland
    – kashish
    Sep 11, 2015 at 9:18
  • this is not the solution.
    – WaQaR Ali
    Sep 11, 2015 at 9:41
0

There are two possibility / ways.

  1. Add css.

    #block-user-0 .item-list  { display: none;}
    
  2. Show link in your module.

    if(isset($tabs['#primary'][1]['#link']['path']) && $tabs['#primary'][1]['#link']['path'] == 'user/password') { show($tabs['#primary'][1]); }

Hope this can solve your problem.

10
  • Viraj : please tell me where to add these 1 and 2 code which u have provided
    – kashish
    Sep 11, 2015 at 9:21
  • Kashish : In page.tpl.php
    – Viraj
    Sep 11, 2015 at 9:39
  • #block-user-0 .item-list { display: none;} this and 2nd one do we need to keep in page.tpl.php?? m in learning stage ....m sorry
    – kashish
    Sep 11, 2015 at 9:40
  • viraj: after adding i am my login screen looks as above ...i have attached screen shot, please do check
    – kashish
    Sep 11, 2015 at 9:46
  • For that, i need to go through what you did, Where you did. ?
    – Viraj
    Sep 11, 2015 at 9:53

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.