Java – how to store encrypted passwords in the database?

I try to store the password in the database in encrypted form with the help of JSP and servlets How can I do that?

Solution

The self - made algorithm has security risks and is very painful to maintain

Use the bcrypt algorithm provided by jbcrypt (open source):

// Hash a password
String hashed = BCrypt.hashpw(password,BCrypt.gensalt());

// Check that an unencrypted password matches or not
if (BCrypt.checkpw(candidate,hashed))
    System.out.println("It matches");
else
    System.out.println("It does not match");

If you use maven, you can Insert the following dependencies into XML to obtain the library (please tell me if there is an updated version):

<dependency>
    <groupId>de.svenkubiak</groupId>
    <artifactId>jBCrypt</artifactId>
    <version>0.4.1</version>
</dependency>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>