Title: Before Login Action
Last modified: August 19, 2016

---

# Before Login Action

 *  [brandonhansen](https://wordpress.org/support/users/brandonhansen/)
 * (@brandonhansen)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/before-login-action/)
 * I am working on an plugin for wordpress that will check against an external database
   to see if the user is a member of that site. If they are, and they don’t have
   a wp login, then the plugin will need to create a login for them. I have everything
   working (at least in isolation/unit testing), but what I cannot figure out is
   how to hook into the login process.
 * Basically what I need to happen is when the login form is submitted, I first 
   need wp to call my function in my plugin. My plugin will then either create a
   new user (if needed), then I will let wp continue with login.
 * How can I do that? Is there an action that I am missing?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Eric Mann](https://wordpress.org/support/users/ericmann/)
 * (@ericmann)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/before-login-action/#post-1219979)
 * When a user logs in, WordPress checks their credentials against its own database.
   If things check out, it creates a cookie with their username, and password and
   then redirects the user to whatever page they’re supposed to go to.
 * Right before WP redirects the user, it does the action “wp_login” and passes 
   the $user_login variable.
 * You can hook into this action and check to see if this login is also in your 
   external database …
 *  Thread Starter [brandonhansen](https://wordpress.org/support/users/brandonhansen/)
 * (@brandonhansen)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/before-login-action/#post-1219984)
 * Yeah, I know that I can do that, but the problem is that they won’t be a member
   if this is the first time that they have visited the wp site. The way I am hoping
   to do it is when they submit the form, then I would be able to check the external
   db. Then I check the wp db. If they are a member, continue, and let wp log them
   in. If not, then create a membership for them in wp (with the credentials that
   are sent from the external db). So is there a way to hook in BEFORE the attempted
   login not after?
 * On second thought, does wp_login happen whether the login was a success or not?
   If it does, then what I might be able to do is to create the user if there is
   no user found, and then somehow trigger that login attempt again.
 *  Thread Starter [brandonhansen](https://wordpress.org/support/users/brandonhansen/)
 * (@brandonhansen)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/before-login-action/#post-1220042)
 * I ended up just hooking into the “failed_login” action. That worked perfectly.
 *  [Eric Mann](https://wordpress.org/support/users/ericmann/)
 * (@ericmann)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/before-login-action/#post-1220044)
 * In that case, I’d recommend hooking in to WordPress’ authentication system. The
   action name is ‘wp_authenticate’ and it passes an array (array(&$user_login, &
   $user_pass)) as the variable.
 * But to answer your other question, the wp_login action is called when you have
   a successful login.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Before Login Action’ is closed to new replies.

 * 4 replies
 * 2 participants
 * Last reply from: [Eric Mann](https://wordpress.org/support/users/ericmann/)
 * Last activity: [16 years, 7 months ago](https://wordpress.org/support/topic/before-login-action/#post-1220044)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
