"How long do you have to have been working until you can get a mortgage?"

Would this sentence be grammatical? If not, how would it sound using proper grammar?