It would be specific to the laws of your country. In the UK asking for a username and password probably breaches data protection laws, although there is not much case law to support this.
I found this document relating to Irish law. it says:
There is no Irish legislation prohibiting an employer requesting login details. However, when an employer reviews a job candidate’s social media accounts, two issues should be considered.
Candidates are protected by the employment equality legislation which prohibits discrimination on the grounds of gender, civil or family status, sexual orientation, religious belief, age, disability, race or nationality or membership of the Traveller community. An employer could be liable under equality legislation if a candidate can show that the reason he/she was not offered a job was connected with material relevant to one of the prohibited grounds and seen by the prospective employer on the candidate’s social media accounts.
Data protection legislation and guidance issued by the Data Protection Commissioner suggests that employers must, at a minimum, advise candidates that online screening will take place, explain what form it will take and why screening is considered necessary having regard to the nature of the job. Other data protection obligations, including how a candidate’s personal data gleaned in the screening process should be stored and protected from unnecessary dissemination, must also be considered.