Amend wordpress password function

Why to edit the whole form ? Filters are good because they gives you the current output and you just need to add your string to it then return it back to WordPress.

In above example you are not using it so let use it.

Example:-

add_filter('the_password_form', function( $form ){
    $my_html="<h2><br>Password Protected Area</h2>";
    return $my_html . $form;
});