title: Spring Boot How to check if encoded password from db is matching with password from a form before an update
body: <p>I implement a method inside my update method for check if the given password in a UpdateForm is matching with an encoded password from db.<br>
  I didn't found any tutorial or solution already but I've tried some stuff but nothing work.<br>
  This is my update method</p>
  
  <pre><code>@RequestMapping(value = {"/home/editUser"}, method = RequestMethod.POST)
  public String home(@ModelAttribute("editUser") User editUser, Model model) {
      logger.info("/home/editUser");
      try {
          User user = userService.findById(editUser.getId());
          if (!user.equals(editUser)) {
              //old password matching
              if (user.getPassword_1() == editUser.getPassword_1()) {
                  //encode new password
                  editUser.setPassword(PassEncoding.getInstance().passwordEncoder.encode(editUser.getPassword()));
                  //update
                  userService.update(editUser);
                  model.addAttribute("msg", "success");
              }
              else {
                  System.out.println("not match");
              }
          } else {
              model.addAttribute("msg", "same");
          }
      } catch (Exception e) {
          model.addAttribute("msg", "fail");
          logger.error("editUser: " + e.getMessage());
      }
      model.addAttribute("home", editUser);
      return "home";
  }
  </code></pre>
  
  <p><code>Password_1</code> is my <em>oldpassword (actual)</em> , but I don't know how I can implement the password encoder and it gives  </p>
  
  <blockquote>
    <p>not match</p>
  </blockquote>
  
  <p>Thanks in advance for help :)</p>
  
  <p>I've just tried</p>
  
  <pre><code>if(PassEncoding.getInstance().passwordEncoder.matches(editUser.getPassword_1(), user.getPassword_1()))
  </code></pre>
  
  <p>but it gives</p>
  
  <blockquote>
    <p>not match</p>
  </blockquote>
  
  <p>It's work with </p>
  
  <pre><code>if(PassEncoding.getInstance().passwordEncoder.matches(editUser.getPassword_1(), user.getPassword()))
  </code></pre>
  
  <p>Thanks a lot !</p>