In the USA, outside of California and possibly a few other states, it isn't clear this is legal. Employers may be able to prohibit employees from publishing their salaries, although they can't prohibit employees from discussing compensation with each other.