I'm a U.S. citizen, married to a man from Mexico. He came to the U.S on a student visa, and then stayed on after graduation, with no immigration papers. He works at various restaurant jobs, all under the table. I also work, but only part-time. We have one child. We've been married for several years, and have finally saved up enough to pay all the fees to get him a U.S. green card. It seems like I might be able to avoid filling out an Affidavit of Support (Form I-864) for him, since the instructions basically say that if we've racked up 40 qualifying Social Security quarters between us during our marriage, I'm off the hook. But what about the fact that he was working illegally? Will that mean the work doesn't count, or will it get him in trouble?
The real question here is whether your husband was working with a valid Social Security number. The immigration laws do not require, in the case of qualifying for an exemption from the I-864 Affidavit of Support requirement, that the noncitizen's work have been done with authorization from the immigration authorities – the laws simply require that the applicant satisfies the requirements of the Social Security Administration (SSA) regarding credit for work done. And to be credited with work quarters according to the SSA, the work needs to have been performed in the name of the person whose number it really is.
It may be that your husband obtained a valid Social Security Number during his time as a student, if he got work authorization then. If so, any work your husband did using that number should count in tallying up his quarters for Social Security purposes. (He will also need to have earned more than a minimum amount per year; and this amount changes every year, so you'll need to do some careful checking.)
To check your husband's SSA earnings record (and yours, too), each of you will need to go to the "My Social Security" page of the SSA website and open an account. (Your lawyer, if you eventually go to one, will be very interested to see the printout of what you find here.)
The immigration laws do have many ways of punishing someone for illegal work, but in the case of someone who worked with a valid Social Security Number, entered the U.S. legally, and is marrying a U.S. citizen, it's unlikely to affect your green card case – though you really should save up enough money to see an immigration lawyer for a full analysis. This is a tricky area of the law, and a small difference in one's personal situation can make a big difference in the legal result.
If your husband used another person's Social Security Number, or a false number, in order to work, this will not count toward the 40 quarters. Again, it would be worth consulting an experienced immigration attorney to see whether there's a way to fix this situation.