Decode the Bcrypt encoded password in Spring Security to deactivate user account

前端 未结 2 810
野趣味
野趣味 2021-02-01 18:05

I am working on web application project in Spring Hibernate MVC. I am storing encoded passwords in a database using Bcrypt algorithm in Spring security.

Now I want to get

2条回答
  •  隐瞒了意图╮
    2021-02-01 18:29

    BCryptPasswordEncoder bcrypt = new BCryptPasswordEncoder();  
    boolean isPasswordMatches = bcrypt.matches(userenteredpasswordWithotEncryoted, encryptedPasswordFromDb);
    

    Example:

    boolean isPasswordMatches = bcrypt.matches(
            "Truck123",
            "$2a$10$kcVH3Uy86nJgQtYqAFffZORT9wbNMuNtqytcUZQRX51dx6IfSFEd."
    );
    
    
    if (isPasswordMatches) { // correct password
        ...
    } else { // Wrong Password
        ...
    }
    

提交回复
热议问题