How to disable browser autocomplete for the login form I would like to remove auto fill user name and password while login or forgot password.

I have tried this but its not working: 

if ($form_id == 'user-login-form') {
  $form['name']['#attributes']['autocomplete'] = 'off';
} 


What am I doing wrong?
You can try:

$form['account']['name']['#attributes']['autocomplete'] = 'off';