How to modify login process in drupal

You want to do the following stuffs

To add validation during login process of drupal

To redirect to user specific pages in drupal

To create session variables during login process of drupal

Display a message after successful login in drupal

To archive above you need to use drupal’s  “hook_user_login” hook.

Create a module and name it as mylogin.

Open the mylogin.module file and write the following codes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function mylogin_user_login(&$edit, $account, $user = NULL)
{
    global $user;
    if(isset($user->uid) && $user->uid != '' && $user->uid != 0)
    {
       /*
        * write down your codes here
        * like in my case i want to redirect my user's to myNewProfile page
        * Show below is the code
        */
 
        $redirection = 'myNewProfile';
        if ($_POST['form_id'] != 'user_pass_reset')
        {
           $_GET['destination'] = $redirection;
        }
    }
}

 Display a Custom message after successful login in drupal

function mylogin_user_login(&$edit, $account, $user = NULL)
{
    global $user;
    if(isset($user->uid) && $user->uid != '' && $user->uid != 0)
    {
        drupal_set_message(t('Welcome to your profile'));
        $redirection = 'myNewProfile';
        if ($_POST['form_id'] != 'user_pass_reset')
        {
           $_GET['destination'] = $redirection;
        }
    }
}