How to mass reset passwords

Issue

  • We need to reset the passwords of all of our users. Due to the amount of users we have, it would be difficult doing this manually. Is this functionality available out of the box, or is there a best approach to it?

Environment

  • Liferay DXP 7.3+

Resolution

  • Unfortunately mass resetting passwords is not something that is available in OOTB Liferay.
  • This, however, could be achieved via the use of a groovy script. We are listing a proof of concept script below that was drafted for a Liferay DXP 7.3 environment, you may need to adjust it according to your needs.
     
    import com.liferay.portal.kernel.model.User;
    import com.liferay.portal.kernel.service.UserLocalServiceUtil;

    long companyId = 12345;

    List<User> users = UserLocalServiceUtil.getCompanyUsers(companyId, -1, -1);

    for (User user : users) {
    out.println("This user will get a password reset mail: " + user.getUserId())
    // UserLocalServiceUtil.sendPasswordByUserId(user.getUserId());
    }
     
  • Please note that in order to fetch the userIds, we previously used the getCompanyUsers() method, which returns a range of all the users belonging to the company. First this script prints out the userIds belonging to the users that will receive a Password Reset Email, so you may adjust the range if needed, then you may uncomment the last line that actually sends out the mass mails.

Additional Information

这篇文章有帮助吗?
0 人中有 0 人觉得有帮助