0

Let us suppose to have a bean:

@Bean
PasswordEncoder getPasswordEncoder()
{
  return new BCryptPasswordEncoder();
}

and on the html page:

 <div class="form-group">
        <label> Confirm Password</label>
        <input type="password" class="form-control" th:field="*{confirmPassword}">
    </div> 

Is there any way to call BCryptPasswordEncoder().someFunction() on th:field before its value is send through submit?

Discipulos
  • 423
  • 8
  • 23
  • 1
    You cannot use Thymeleaf to process user-provided input like that. Thymeleaf only exists on the server. It replaces itself with rendered HTML. You could use JavaScript and an Ajax call, or some such, instead. (I am not a security expert so I am going to steer clear of the debates surrounding the benefits and dangers of passing a hashed password back to the client. Except to say: at least make sure you are using end-to-end SSL for all your traffic.) – andrewJames Jul 15 '22 at 19:43

1 Answers1

0

Simple answer, No.

Thymeleaf is a rendering engine so it can only do things before the html is served to the end user. If you'd have a need to validate a field before submiting the form you either have to do validation in javascript or have some method to validate in the background against server using ajax.

In most cases normal behaviour would be to do validation on form submit and if it is incorrect give feedback to user than

Ralan
  • 651
  • 6
  • 17