2012-09-10 99 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