For every authentication process you must use user's login name and their password and for this we usually stored the password in an encrypted form. You can do this using BasicPasswordEncryptor. The BasicPasswordEncryptor implements the PasswordEncryptor. For encrypting user's password you must use BasicPasswordEncryptor.encryptPassword(String password). I have written following program for you just try to understand it.
Code:
package org.kodejava.example.jasypt;
import org.jasypt.util.password.PasswordEncryptor;
import org.jasypt.util.password.BasicPasswordEncryptor;
public class PasswordEncryptorDemo {
public static void main(String[] args) {
PasswordEncryptor etr = new BasicPasswordEncryptor();
String eq = etr.encryptPassword("secret");
System.out.println("encrypted = " + eq);
if (etr.checkPassword("secret", eq)) {
System.out.println("Welcome to this page");
} else {
System.out.println("Invalid password, access denied!");
}
}
}
Bookmarks