Ironically I recently ran in to a space related issue with usernames on one of my Moodle servers running 2.5+. I suspect what happened was that when the user accounts were created via csv import, the code was not checking and removing the spaces. As a result, I had 4 users with a space at the end of the username. I noticed it because one of them was having trouble logging in (imagine that). When we attempted to update the password there was a message that the user account already existed and no changes could be made to that record. I went in phpmyadmin and did:
SELECT * FROM mdl_user WHERE username LIKE '% ';
to find the others and manually removed the space from them. I agree with Iñaki that one is best to avoid spaces in Moodle usernames. Peace - Anthony