Sometimes bad things happen to bad people.

That might seem a sufficient postmortem on the leak of millions of AshleyMadison.com users’ personal information, and indeed many are expressing the same sentiment: Those cheaters got what they deserved.

“Too bad for those men, they’re cheating dirtbags and deserve no such discretion,” announced the team that took credit for the hack.

Except that the revelations won’t just hurt those seeking adulterous relationships, but innocent spouses and children, too.

And certainly many of the cheaters are likely otherwise fine people, suffered a momentary lapse in judgment and may even have regretted their actions before being outed.

Yet what’s going on here is more than schadenfreude, that apt German term meaning taking pleasure from other’s misery.

Society is supposed to frown on those cheating on their spouses to discourage a behavior that hurts families — and usually the cheaters themselves.

Americans don’t want government trying to police morality, which is why we tend to rely on civil society to create standards that advance everyone’s interests.

Of course, shame can be taken too far, as anyone who has witnessed a Twitter mob or other social-media feeding frenzy can attest.

But it’s also a useful tool in discouraging heavy drinking, drug use, neglectful parenting, sloth and a host of other bad personal habits that aren’t victimless crimes, so to speak.

The men and women who used AshleyMadison.com trusted that they wouldn’t face public opprobrium because of the Web site’s promise of discretion and privacy.

Reportedly, a large share of the users being outed — searchable databases of them have begun popping up online — had e-mail addresses ending with .gov and .edu, suggesting they were respectable members of professional communities, who likely place a high value on their reputations.

That’s really no surprise. In fact, the Web site’s business model depended on the existence of such a public penalty as much as it depended on people’s desire to cheat. The technology was supposed to offer anonymity, allowing people to engage in vice without paying a public cost.

And certainly that promise has an appeal. Just as AshleyMadison.com attracted millions of customers — Americans who never would have set foot into a XXX-rated video store or even the dirty section of the magazine rack surreptitiously visit Internet porn sites, believing that since they are using computers in the privacy of their own home or behind a closed office door, their secret is safe.

The recent avalanche of seized “private” information — from credit-card breaches to hacked government personnel databases to these leaked AshleyMadison.com files — shows us that nothing in cyberspace is actually private.

In fact, the risks of being outed for misdeeds done online may be far greater than of those that take place in the actual physical world. If you can successfully avoid interested eyes during a physical encounter or trip into an unsavory establishment, you are pretty much safe.

But your cyber records can remain available virtually forever.

Americans ought to be concerned about the ease with which hackers are infiltrating supposedly secure databases.

It creates an enormous national-security and economic vulnerability. Cybercrime and intellectual-property theft already drain billions from legitimate businesses, destroying jobs, wealth and innovation that could make us all better off.

But it’s tempting to say it’s for the best that there are no assurances of privacy when it comes to vice. We need society to continue to discourage people from indulging in their worst impulses. The fear of discovery can and should be a useful deterrent.

It’s a shame that so many people are hurting because of the leaked AshleyMadison.com information, but there’s a lesson here for all of us: When it comes to cyberspace, there’s no such thing as privacy, so behave accordingly.

Carrie Lukas is the managing director of the Independent Women’s Forum and vice president for policy of Independent Women’s Voice.