title: Why doesn't match my password with the encodedPassword?
body: <p>I was playing around with Spring Security. There are some PasswordEncoders. Now I heard of Argon2 and the library <a href="https://github.com/phxql/argon2-jvm" rel="nofollow noreferrer">argon2-jvm</a>.
  So I used this library to implement an Argon2 PasswordEncoder.</p>
  
  <pre><code>import de.mkammerer.argon2.Argon2;
  import de.mkammerer.argon2.Argon2Factory;
  import org.springframework.security.crypto.password.PasswordEncoder;
  
  public class Argon2PasswordEncoder implements PasswordEncoder {
  
      private final static Argon2 ARGON2 = Argon2Factory.create();
  
      @Override
      public String encode(CharSequence rawPassword) {
          return ARGON2.hash(2, 512, 1, rawPassword.toString());
      }
  
      @Override
      public boolean matches(CharSequence rawPassword, String encodedPassword) {
          return ARGON2.verify(rawPassword.toString(), encodedPassword);
      }
  }
  </code></pre>
  
  <p>Ok. Now I tested the implementation and with the password <em>"<strong>Password</strong>"</em> I get a hash of <em>"<strong>$argon2i$v=19$m=512,t=2,p=1$RXlcbec6BOFAo7tfgeAp7g$z4mUln5y/ylkmNjoK8u3wmQYQxwBzWyRepQaZlGtSPw</strong>"</em> </p>
  
  <p>But this can't be the hash, I think the hash is the part after <em>p=</em>, isn't it?</p>
  
  <p>Ok, then I tried to matches them and it failed. Why?</p>
  
  <pre><code>System.out.println(encoder.matches("Password", "$argon2i$v=19$m=512,t=2,p=1$RXlcbec6BOFAo7tfgeAp7g$z4mUln5y/ylkmNjoK8u3wmQYQxwBzWyRepQaZlGtSPw");
  </code></pre>
  
  <p>=> false</p>
  
  <pre><code>System.out.println(encoder.matches("Password", "1$RXlcbec6BOFAo7tfgeAp7g$z4mUln5y/ylkmNjoK8u3wmQYQxwBzWyRepQaZlGtSPw");
  </code></pre>
  
  <p>=> false</p>
  
  <p>How can I match them and why are there some of the parameters like paralellism and memory part of the hash?</p>