Sorry if this disappoints you, but it is legal for a potential employer to ask for salary history. Often, the past employer will do no more than confirm that you worked there and for what time period. Companies have become so gunshy about lawsuits, that they routinely advise human resources officials to reveal just the basics on a background check. It's important to understand why employers ask for salary information.
Employers use many screening techniques in the hiring process, including salary history.
If several candidates are equal in experience and skills, and one can be hired more inexpensively than the others, the employer sees this as a good move. From your perspective, it looks like a way to pay you less than you're worth. You have to show the employer the value of your skills and ability. But you can't get that chance if you don't get an interview, and that gets back to your salary history question. Just because they ask for salary history doesn't mean you have to provide it.