Showing health code is the need of epidemic prevention and control, which is not only responsible for others, but also the guarantee of their own safety. China has formulated relevant laws and regulations. If they don't cooperate to show their passwords, the relevant police and security guards can refuse their requests to travel or enter public places.
Health codes are based on real data and can be generated by citizens or people who have returned to work through online declaration and background audit.