User { public boolean checkSecretAnswer(String answer) throws InvalidKeySpecException, NoSuchAlgorithmException { if (answer == null) return false; byte[] salt = Base64.decodeBase64(this.secretAnswerSalt); KeySpec spec = new PBEKeySpec(answer.toCharArray(), salt, 65536, 128); SecretKeyFactory fac = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); byte[] hash = fac.generateSecret(spec).getEncoded(); return Base64.encodeBase64String(hash).equals(this.secretAnswerHash); } User();  User(Long id, String email, String passwordHash, String passwordSalt, String fullName,
            String bio, UserType userType, DietType dietType, String secretQuestion, String secretAnswerHash, 
            String secretAnswerSalt, String avatarUrl, String location, Boolean isBanned); @JsonSetter("password") void setPassword(String password); @JsonSetter("secretAnswer") void setSecretAnswer(String answer); boolean checkSecretAnswer(String answer); boolean checkPassword(String password); @JsonGetter("email") String getEmail(); @JsonGetter("fullName") String getFullName(); @JsonSetter("email") void setEmail(String email); @JsonSetter("fullName") void setFullName(String fullName); @JsonIgnore String getPasswordHash(); @JsonIgnore String getPasswordSalt(); @JsonGetter("id") Long getId(); @JsonSetter("id") void setId(Long id); @JsonGetter("bio") String getBio(); @JsonSetter("bio") void setBio(String bio); @JsonGetter("userType") int getUserType(); @JsonSetter("userType") void setUserType(int userType); @JsonGetter("dietType") int getDietType(); @JsonSetter("dietType") void setDietType(int dietType); @JsonGetter("secretQuestion") String getSecretQuestion(); @JsonSetter("secretQuestion") void setSecretQuestion(String secretQuestion); @JsonIgnore String getSecretAnswerHash(); @JsonIgnore String getSecretAnswerSalt(); @JsonGetter("avatarUrl") String getAvatarUrl(); @JsonSetter("avatarUrl") void setAvatarUrl(String avatarUrl); @JsonGetter("location") String getLocation(); @JsonSetter("location") void setLocation(String location); @JsonGetter("isBanned") Boolean getIsBanned(); @JsonSetter("isBanned") void setIsBanned(Boolean isBanned); static String generatePassword();  }
@Test public void testSecretAnswer() throws Exception { final User fixture = mapper.readValue(fixture("fixtures/user.json"), User.class); assertThat(fixture.checkSecretAnswer("deneme")).isEqualTo(true); assertThat(fixture.checkSecretAnswer("nope")).isEqualTo(false); }