If law was created to enforce proper behavior, I'm pretty sure following the laws is moral.
Slavery was perfectly legal one time?
Some recreational drugs that cause harm to people are legal right now? (alcohol,tobacco)
Laws change all the time, morality generally can't.