How to catch username or password using hook_form_alter I need to catch username/password using the hook_form_alter(). I'm using this code:

function sds_form_alter(&amp;$form, FormStateInterface $form_state, $form_id ) {

  if (in_array($form_id, ['user_login_block_form', 'user_login_form'])) {  
    $username= $form_state-&gt;getValue('name');
    echo "Username Value".$username;
  }

}


but it returns null. What am I missing here?
You can use in VALIDATE function like 

$form['#validate'][] = 'mymodule_user_validate';


In this you can all values even if there is no successful values in it.
But remember to call your function first before default validate function.