Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Jay Trivedi
Liferay Password Problem
14 dicembre 2012 23.52
Risposta

Jay Trivedi

Punteggio: Regular Member

Messaggi: 107

Data di Iscrizione: 23 novembre 2012

Messaggi recenti

Hello Friends,
I am in a big problem,
I already have few users with password stored by liferay, Now i want to create a functionality to change password via code, But for that i need to know that what policy does liferay uses to decrypt and encrypt password. Please i need to encrypt password and compare with the encrypted password in liferay system.

Need to know what encryption policy does liferay follows,MD5 SHA1 etc.
Jelmer Kuperus
RE: Liferay Password Problem
15 dicembre 2012 1.25
Risposta

Jelmer Kuperus

Punteggio: Liferay Legend

Messaggi: 1192

Data di Iscrizione: 10 marzo 2010

Messaggi recenti

Use UserServiceUtil.updatePassword
Jay Trivedi
RE: Liferay Password Problem
15 dicembre 2012 2.56
Risposta

Jay Trivedi

Punteggio: Regular Member

Messaggi: 107

Data di Iscrizione: 23 novembre 2012

Messaggi recenti

Hey Jelmer,
That does works but i need to compare my password with system encrypted password so i need follow same encrypt/decrypt policy as of Liferay does!! and so its more important for me to know the internal methodology. Hope you can help out.

Thanks Jay.
Jelmer Kuperus
RE: Liferay Password Problem
15 dicembre 2012 3.08
Risposta

Jelmer Kuperus

Punteggio: Liferay Legend

Messaggi: 1192

Data di Iscrizione: 10 marzo 2010

Messaggi recenti

What algorithm is used depends on the value of the passwords.encryption.algorithm property in portal.properties

You cannot decode encrypted passwords. They are cryptographic hashes designed to be non reversible

You can use PwdEncryptor.encrypt to encrypt a plaintext password.
Jay Trivedi
RE: Liferay Password Problem
15 dicembre 2012 4.36
Risposta

Jay Trivedi

Punteggio: Regular Member

Messaggi: 107

Data di Iscrizione: 23 novembre 2012

Messaggi recenti

Thanks Jelmer,
But et me make it more clear. If user wants to reset the password then.
1. User must enter his current password.
2. If entered password will be true then user will be redirecred to a new reset page there user can enter the new password.

My Problem is I am not able to make a match for step 2. i.e user just enter password and i get a return value as a Boolean or something, Whether its correct or not. I don't want to user Authenticate By email address. If you can provide me little help by naming method or writing little piece of code. Or even the class name that has any such method can help me a lot. So that i can look into its API.


Thanks Jay.
Jelmer Kuperus
RE: Liferay Password Problem
15 dicembre 2012 4.41
Risposta

Jelmer Kuperus

Punteggio: Liferay Legend

Messaggi: 1192

Data di Iscrizione: 10 marzo 2010

Messaggi recenti

So use PwdEncryptor to encrypt the plaintext password and compare it with the stored password hash for that user (you can get that from user.getPassword)
Jay Trivedi
RE: Liferay Password Problem
17 dicembre 2012 4.17
Risposta

Jay Trivedi

Punteggio: Regular Member

Messaggi: 107

Data di Iscrizione: 23 novembre 2012

Messaggi recenti

Hey Jelmer,

I have my custom Jsp Page with three password fields.
Field1 = Current Password
Field2 = new Password
Field 3 = confirm new Password

 1
 2
 3UserLocalServiceUtil u = new UserLocalServiceUtil();
 4        try
 5        {
 6            String pwd1  = actionRequest.getParameter("password0");
 7            String pwd2  = actionRequest.getParameter("password1");
 8            String pwd3 = actionRequest.getParameter("password2");
 9            
10                User user = u.updatePasswordManually(userId, pwd2, true,false,new Date());
11        }


But it stores password in plain text. i don't want to use the reset option as it redirects me on another page.

and PasswordEncryptor method is not found any more.
Jelmer Kuperus
RE: Liferay Password Problem
18 dicembre 2012 1.18
Risposta

Jelmer Kuperus

Punteggio: Liferay Legend

Messaggi: 1192

Data di Iscrizione: 10 marzo 2010

Messaggi recenti

Sorry PwdEncryptor is in portal-impl

Try something like this

 1import com.liferay.portal.kernel.exception.PortalException;
 2import com.liferay.portal.kernel.util.MethodKey;
 3import com.liferay.portal.kernel.util.PortalClassInvoker;
 4
 5public class PwdEncryptor {
 6
 7    private static final String DELEGATE_CLASS_NAME =
 8            "com.liferay.portal.security.pwd.PwdEncryptor";
 9
10
11    private PwdEncryptor() {
12    }
13
14    public static String encrypt(String clearTextPassword)
15        throws Exception {
16
17        MethodKey key = methodKeyFor("encrypt", String.class);
18        invokePortalClassMethod(key, clearTextPassword);
19    }
20
21    private static MethodKey methodKeyFor(String methodName, Class<?>... parameterTypes) {
22        return new MethodKey(DELEGATE_CLASS_NAME, methodName, parameterTypes);
23    }
24
25    private static Object invokePortalClassMethod(MethodKey key, Object... arguments) throws PortalException {
26        try {
27            //noinspection unchecked
28            return PortalClassInvoker.invoke(false, key, arguments);
29        } catch (PortalException e) {
30            throw e;
31        } catch (Exception e) {
32            throw new RuntimeException(e);
33        }
34    }
35}
Jay Trivedi
RE: Liferay Password Problem
19 dicembre 2012 7.07
Risposta

Jay Trivedi

Punteggio: Regular Member

Messaggi: 107

Data di Iscrizione: 23 novembre 2012

Messaggi recenti

Thaks a Lot Jelmer. emoticon


Regards
Jay.