Password history validation while using custom DB


How we can implement password history validation while using custom DB. I tried to put this code in change_password.js custom DB script but I couldn’t find a way to return an error message. If I am returning something like callback(new Error('custom error')), It is redirecting to our return_url` with some error message in URL.

I wish to display the password history error message above the input fields.

Also, it seems that password history option given on password policy tab doesn’t work in case of custom DB. Please confirm and suggest a way to do it.