Sunday, 26 November 2017

Encrypted Passwords in Liferay

Basically when you create a user programmatically we may face issue in password creation.

To avoid that its always better to go with the default APIs of liferay.

For Ex:

UserLocalServiceUtil.addUser(creatorUserId, companyId, autoPassword, password1, password2, autoScreenName, screenName, emailAddress, facebookId, openId, locale, firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);


But you may come across some place where you may need to use

UserLocalServiceUtil.addUser(user);

So at that time We need to encrypt the plain text password

So we can use Liferay's PasswordEncryptorUtil to encrypt our plain text.

user.setPassword(PasswordEncryptorUtil.encrypt("test"));
user.setPasswordUnencrypted("test");
user.setPasswordEncrypted(true);

UserLocalServiceUtil.addUser(user);

Even we can use

PasswordEncryptorUtil.encrypt(algorithm, plainTextPassword, encryptedPassword);

to select the algorithm.

TEST

I am Java Developer. I have 6 year Experiance in this field and like to post in blogging. So keep sharing and like my post

0 comments:

Post a Comment

 

Copyright @ 2017 Liferay Article.