How can we make a website authenticated user autologin to wordpress?

I have a Web application where the users will be authenticated before they use it. The help documentation for this application is maintained using WordPress installed on a different server (If needed the WordPress instance can be installed on the same server also). In order to access the documentation also, user must be authenticated and now this is done using a WordPress plugin.

Now i want to make the authentication process common for all. i.e User comes to the web application, then login to use the application and they can click the ‘documentation’ link within the application and user automatically login into the WordPress also. How can i implement this?

Related posts

Leave a Reply

1 comment

  1. I have had to do something similar before where a user had to click a link in an email and it automatically logged them in.

    I added the following to my themes header.php

    if (!is_user_logged_in())
    {
      if (isset($_GET['u']) && !empty($_GET['u']))
      {
        $u = $_GET['u'];
        $result = $wpdb->get_row($wpdb->prepare("SELECT * FROM wp_users WHERE md5(concat(user_login,'SOMESECRETPHRASE',user_email)) = '%s' AND user_login != 'admin'",$u));
        if (isset($result->ID) && isset($result->user_login))
        {
            wp_set_current_user($result->ID, $result->user_login);
            wp_set_auth_cookie($result->ID);
        }
      }
    }
    

    The the users login link is created by Adding /?u=".md5($user_login."SOMESECRETPHRASE".$user_email)
    To the end of the link

    They will then automatically be logged into wordpress as the correct wordpress user.