You should just let the password field have kilobytes of data. Throw a warning, but it costs you almost nothing. You don’t have to store the data, processing password hashes is designed to take a long time and use a lot of memory (way more than the password of a few KB).
Your web app should also not engage with the password field as much as possible. Don’t make it a component, just leave it a password field. Don’t read it except to immediately send the contents to the server. Bonus points for just having that be a form submission.