Giving a default value to a password element in D7 form API? I wrote a custom feeds fetcher class that does an authentication call before it gets the feed. In its settings, I have username and password fields in the form. I tried to set the field #type to password, but it seemed not to use the #default_value element, thus obliterating the saved password when you hit the 'save' button.

This maintains the password, but shows it in plaintext:

$form['password'] = array(
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('Password'),
  '#description' =&gt; t(''),
  '#default_value' =&gt; $this-&gt;config['password'],
);


This shows dots for the password, but does not populate the field using the #default_value, causing you to have to enter the password any time you want to change and save any value on the form:

$form['password'] = array(
  '#type' =&gt; 'password',
  '#title' =&gt; t('Password'),
  '#description' =&gt; t(''),
  '#default_value' =&gt; $this-&gt;config['password'],
);


I need to be able to have the user enter a password and have it stay no matter what other values they change on the form and save. Does this preclude me from using the password field type, since it appears not to use the #default_value element?
You can try to add your default value directly with #attributes option just like that : 

$form['password'] = array(
  '#type' =&gt; 'password',
  '#title' =&gt; t('Password'),
  '#description' =&gt; t(''),
  '#attributes' =&gt; array('value' =&gt; $this-&gt;config['password']),
);


After I'm not sure if you will be able to get that value on validate and submitcallback, you should check.