How to mass reset passwords
Written By
Peter Schwarcz
How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!
While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.
Legacy Article
You are viewing an article from our legacy "FastTrack"
publication program, made available for informational purposes. Articles
in this program were published without a requirement for independent
editing or verification and are provided"as is" without
guarantee.
Before using any information from this article, independently verify its
suitability for your situation and project.
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?
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.
Did this article resolve your issue ?