2012-09-10 68 views
2

我在Liferay中实现了一个单独的更改密码模块,具体而言,扩展了登录Portlet,使得它在登录时具有更改密码。在Liferay中基于密码策略的密码语法检查

我试着调用struts动作enterprise_admin/edit_user,但它不起作用,但我已通过获取该用户的密码策略并检查该类中的minUpperCase等来实现我自己的密码检查器,但有没有一种方法可以让我可以检查语法,无需循环密码并计算minUpperCase等。

Liferay是否有检查密码是否适用于密码策略的具体方法?

回答

0

你可以试试这个。这是他们在UserLocalService

PasswordPolicy passwordPolicy = passwordPolicyLocalService.getDefaultPasswordPolicy(companyId); 
PwdToolkitUtil.validate(companyId, 0, password1, password2, passwordPolicy); 
1

怎样做,如果你没有看到PwdToolkitUtil你可以尝试这样说:“在登录时更改密码”功能

Object[] arguments= {user.getCompanyId(), user.getUserId(), password, password, passwordPolicy}; 
MethodKey methodKey = new MethodKey("com.liferay.portal.security.pwd.PwdToolkitUtil", "validate", long.class, long.class, String.class , String.class, PasswordPolicy.class); 
PortalClassInvoker.invoke(false, methodKey, arguments); 
0

如果你只自定义登录因为的,您也可以使用门户的默认行为UserLocalServiceUtil.updatePassword,而不是第四个参数:

public static User updatePassword(long userId, 
            String password1, 
            String password2, 
            boolean passwordReset, 
            boolean silentUpdate) 
         throws PortalException, 
           SystemException 

Updates the user's password, optionally with tracking and validation of the change. 

Parameters: 
    userId - the primary key of the user 
    password1 - the user's new password 
    password2 - the user's new password confirmation 
    passwordReset - whether the user should be asked to reset their password the next time they login 
    silentUpdate - whether the password should be updated without being tracked, or validated. Primarily used for password imports. 
Returns: 
    the user 
Throws: 
    PortalException - if a user with the primary key could not be found 
    SystemException - if a system exception occurred