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
- You may also use other methods according to your needs from the UserLocalServiceUtil class, which can be found here: https://github.com/liferay/liferay-portal/blob/7.3.x/portal-kernel/src/com/liferay/portal/kernel/service/UserLocalServiceUtil.java
Contenido exclusivo para suscriptores.
Una Suscripción Enterprise de Liferay proporciona acceso a más de 1.500 artículos que incluyen las mejores practicas, diagnóstico de problemas y otras soluciones útiles. Inicia sesión para tener un acceso completo.
Inicia sesión