How do I create a WP user outside of WordPress and auto login?

I’ve built a directory of members on a non-WP site (using php and mysql). Each member can log in and update their details using a username and password.

I want to be able to get this to automatically create a user on the WordPress site using the details from the directory of members. Ideally, if they update their details on the directory of members the their user details on the WP site will update. I am not sure how this would work in terms of passwords. Both the WP and directory of members sites are on the same server and so can access each database.

Read More

I’d also be able to have a link on the Directory of members that will take them to the WP site automatically logging them in. I’m not sure about this last point, particularly due to security, however I just want to avoid them having to re-enter their username and password.

Is there a way to achieve the above, ideally using something that already exists?

Related posts

Leave a Reply

2 comments

  1. If you can write the non-wp site to work with the users and usermeta table then you can use wordpress to create and verify the login cookies. If this is not an option, you can do something along the lines of checking for the login information from the other site in wordpress and if it exists and is in the proper format, use wp_signon() to create the wordpress login cookie.

  2. So you’re asking for, basically, two things.

    1. authentication from an external application (the non-WP site)
    2. single sign on (logging in to your non-WP site also logs them in to your WordPress site).

    A common way of doing this is building an authentication service on top of your non-WP site which the WordPress will use. The non-WP site will return a login token to the WP site. Store that token in a cookie.

    An example use case would be:

    1. User lands on your WP site. He attempts to login.
    2. WP sends those credentials to the non-WP site for authentication. Upon success, the non-WP site returns a token. The token means that the credentials were valid.
    3. Add the token to a cookie or a session.
    4. Send user to a logged in page on your WP site.

    HTH