26

Spring Hibernate MVC で Web アプリケーション プロジェクトに取り組んでいます。Spring セキュリティの Bcrypt アルゴリズムを使用して、エンコードされたパスワードをデータベースに保存しています。

ここで、エンコードされたパスワードをデコードして使用アカウントを非アクティブ化したいと考えています。ユーザーがアカウントを非アクティブ化する前に、確認するためにユーザーの電子メールとパスワードを提供しています。デコードされたパスワードの取得に問題があります。

誰かがそれから抜け出すのを手伝ってくれますか、それとも私の要件に対する代替ソリューションですか?

4

2 に答える 2

37

この問題は、以下のコードを使用して解決されます。

BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();  
encoder.matches(password, user.getPassword());  

password- フォーム(JSP)
user.getPassword()から - データベースから

BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
if(email.equalsIgnoreCase(user.getEmail()) && encoder.matches(password, user.getPassword())) {
    userService.deactivateUserByID(user.getId());
    redirectAttributes.addFlashAttribute("successmsg", "Your account has been deactivated successfully.");
    model.setViewName("redirect:/logout");
}else{
    redirectAttributes.addFlashAttribute("errormsg", "Email or Password is incorrect");
    model.setViewName("redirect:/app/profile/deactivate");
}
于 2014-11-13T11:58:56.017 に答える