Trim leading and trailing spaces and all other whitespace. It is actually a good practice for all common fields.
Do not count these trailing and leading spaces towards minimum password length.
Spaces in the middle of password are just fine. Please, never restrict what password can contain.