How do I modify and then render the Drupal login form in a page template in Drupal 7? I'm working on building a custom Drupal 7 theme using bootstrap. One of the things I want to achieve is a login form that is part of the standard page template, rather than sitting alone on its own login page.

Much like on pages like this, for example, where if you are not logged in, the login form sits on each page so you can log in directly from there.

I also need to modify the rendered form to use bootstrap containers and classes, so instead of just rendering the standard form, I need to wrap the form elements in divs with "col-md-4" etc classes.

Can anyone advise or direct me to any documentation on how to achieve this. I'm sure you know that for a beginner, Drupal can be very confusing!
1 )
Create the login and password empty page files and place them in your theme "templates" folder.
The name of the files are page--user--login.tpl.php and page--user--password.tpl.php. There's no need of all those steps of "hook", "alter", blablabla... Drupal will use those files automatically without any call or whatever.

2 )
Put this code inside your files.

page--user--login.tpl.php

&lt;?php print $messages; ?&gt;
&lt;?php print drupal_render(drupal_get_form('user_login')); ?&gt;
&lt;a href="user/password"&gt;Request new password"&lt;/a&gt;


page--user--password.tpl.php

&lt;?php print $messages; ?&gt;
&lt;?php print drupal_render(drupal_get_form('user_pass')); ?&gt;
&lt;a href="user/login"&gt;Go back&lt;/a&gt;


3 )
Done!
In thee steps. Now style your css as much you need and pimp your new fancy login page. "Inspect" your html output of your new login page and see how clean it is now. ; D

Afterwords )

I just spent this last hour reading posts and questions about this all over the internet, and the work around in some cases are simply crazy like using the dpm(get_defined_vars()); function, copying html and paste all of those input forms and attributes, blablabla.
I didn't found a concise post like this. It's crazy!!!

Also, you will need (if you still don't have it and if you want it) to disable "label/description" and enable "placehover" for the inputs. You can do it all together like this:

&lt;?php
/*
 *  Remove labels and add HTML5 placeholder attribute to login form
 */
function THEMENAME_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ( TRUE === in_array( $form_id, array( 'user_login', 'user_login_block') ) )
    $form['name']['#attributes']['placeholder'] = t( 'Username' );
    $form['pass']['#attributes']['placeholder'] = t( 'Password' );
    $form['name']['#title_display'] = "invisible";
    $form['pass']['#title_display'] = "invisible";
}
/*
 *  Remove login form descriptions
 */
function THEMENAME_form_user_login_alter(&amp;$form, &amp;$form_state) {
    $form['name']['#description'] = t('');
    $form['pass']['#description'] = t('');
}
?&gt;


PS )
Do you have the "header", "footer" and "sidebar" visible and want to remove them too? No problem.
Go to admin/structure/block and click "configure". Scroll down and include this on "Show block on specific pages" option:

user/login
user/password


Done!
Drupal it's incredible powerful. I think people complicate things a lot and if you see it in a simple way it will be more efficient... Most of the things you can do it inside Drupal environment.

source: https://www.drupal.org/node/1195754