Example usage for com.liferay.portal.security.pwd PwdAuthenticator authenticate

List of usage examples for com.liferay.portal.security.pwd PwdAuthenticator authenticate

Introduction

In this page you can find the example usage for com.liferay.portal.security.pwd PwdAuthenticator authenticate.

Prototype

public static boolean authenticate(String login, String clearTextPassword, String currentEncryptedPassword)
            throws PwdEncryptorException 

Source Link

Usage

From source file:com.liferay.portlet.myaccount.action.EditUserAction.java

License:Open Source License

@Override
protected Object[] updateUser(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    String currentPassword = actionRequest.getParameter("password0");
    String newPassword = actionRequest.getParameter("password1");

    if (Validator.isNotNull(currentPassword)) {
        if (Validator.isNull(newPassword)) {
            throw new UserPasswordException(UserPasswordException.PASSWORD_LENGTH);
        }//from  w w  w  .  ja va  2s  . co  m

        Company company = PortalUtil.getCompany(actionRequest);

        String authType = company.getAuthType();

        User user = PortalUtil.getSelectedUser(actionRequest);

        String login = null;

        if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
            login = user.getEmailAddress();
        }
        if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
            login = String.valueOf(user.getUserId());
        }
        if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
            login = user.getScreenName();
        }

        boolean validPassword = PwdAuthenticator.authenticate(login, currentPassword, user.getPassword());

        if (!validPassword) {
            throw new UserPasswordException(UserPasswordException.PASSWORD_INVALID);
        }
    } else if (Validator.isNotNull(newPassword)) {
        throw new UserPasswordException(UserPasswordException.PASSWORD_INVALID);
    }

    return super.updateUser(actionRequest, actionResponse);
}