It is important to encrypt user password before storing it in the database. Password must be interpreted only by your java application.
Here is the sample java code to encrypt a plain password text. Before comparing password, encrypt it using following java code.
Sample Java Code
public synchronized String encrypt(String plainpassword) throws SystemUnavailableException {
MessageDigest md = null;
try
{
md = MessageDigest.getInstance("SHA");
}
catch(NoSuchAlgorithmException e)
{
throw new SystemUnavailableException(e.getMessage());
}
try
{
md.update(plainpassword.getBytes("UTF-8"));
}
catch(UnsupportedEncodingException e)
{
throw new SystemUnavailableException(e.getMessage());
}
byte data[] = md.digest();
String encryptedPassword = (new BASE64Encoder()).encode(data);
return encryptedPassword;
}
Welcome to Java Junction. Java junction talks about latest Java & related Web Technology.
Subscribe to:
Post Comments (Atom)
ORM Framework for Kotlin
In Kotlin, ORM (Object-Relational Mapping) libraries provide a convenient way to interact with databases using object-oriented programming p...
-
Feature Comparison Feature Liferay(5.1+) JBoss Portal(2.7) Out of the box Tools Has rich set of out of the box portlets Not too muc...
-
OSGi technology is Universal Middleware. OSGi technology provides a service-oriented, component-based environment for developers and offers...
No comments:
Post a Comment