I don't know exactly how Rails handles this but if I were writing this manually, say in PHP, then to get entered form data back into the form, after a validation error, then I would have to render the data back into each input's value attribute.
There is nothing technically preventing me from doing that with password inputs but it would mean that I would have to pass their own password back to them, in plain text. This, I think, is a deal breaker, because it provides another opportunity for the password to get intercepted.
After reading around on this subject, it seems that a number of people consider this to also be a form of "storing" the password in plain text which is clearly bad. However, it is not at all clear to me why it is considered "storing" a password as the server clearly would not need to store the plain text password anywhere, beyond in the very same variable that was used to receive the plain text password in the first place. However, it may be that they mean that the password is stored in the HTTP response which is then essentially the same concern that I raise above.
Another reason I have seen is that to insert the password back into the password input would require using the value attribute. Whilst this would obscure the password in the rendered input, the password would be visible when inspecting the source using e.g. Firebug. For me, this is a non-issue because it is trivial to turn the type of an input from password to text and reveal the password anyway, or just use JS. It is absolutely incorrect to think that a password field provides much built in security beyond obscuring the password visually.
What you could do is:
- Hash the password (presuming it, itself, passes validation) and store that even if the rest of the data fails validation
- Disable the password fields on the returned form or otherwise indicate to the user that the password they have submitted has been accepted but the rest of the form data needs to be fixed.
- Optionally provide a way for the user to reactivate the password fields, if they decide they want a different password.
- Run a cron task that regularly cleans the database of any orphaned password entries where a user, for whatever reason, didn't bother to continue signing up but did submit the form with errors, at least once.
I can't immediately see how that would compromise security in any way.
Another approach would be to have a multi-step form and have the password and password confirmation inputs on their own, in the last step. That way, you can ensure the rest of the data is valid by the time the user has reached the password stage and if they have any errors in their passwords (for example the password and password confirmation do not match) then you could argue it is reasonable to then render both fields blank as the user won't be able to easily fix the problem with the passwords obscured.