Title: Adding custom login authentication
Last modified: August 21, 2016

---

# Adding custom login authentication

 *  [JazzyP](https://wordpress.org/support/users/jpiionefourone/)
 * (@jpiionefourone)
 * [12 years ago](https://wordpress.org/support/topic/adding-custom-login-authentication/)
 * Hi guys,
 * I have added custom fields on registration to allow the user to input their own
   password and have also created code to generate a verification code which then
   gets emailed over to the user. Of course, the users needs to click the link in
   the email before they can log in.
 * Here’s where I am stuck. I am trying to add my own authentication to check the
   status of the verification when the user tried to log in.
 * Here’s my code which isn’t working;
 *     ```
       function check_validation_status($username) {
       	$user = get_user_by('login', $username);
       	$userID = $user->ID;
   
       	$status = get_user_meta($userID, 'verified', true);
   
       	if($status == '0') {
       		return;
       	}
       }
   
       add_action('wp_authenticate', 'check_validation_status');
       ```
   
 * Unfortunately this code doesn’t seem to do anything. I have also tried the following(
   hooking into a different action)
 *     ```
       function check_validation_status($username) {
       	$user = get_user_by('login', $username);
       	$userID = $user->ID;
   
       	$status = get_user_meta($userID, 'verified', true);
   
       	if($status == '0') {
       		wp_logout(); // works but doesn't show an error :(
       	}
       }
   
       add_action('wp_login', 'check_validation_status');
       ```
   
 * This code is successfulling logging the user straight out if they are not verified
   however it shows no form of error to the user, they just get redirected straight
   back to the login page.
 * Any help will be greatly appreciated.
 * Thanks.
 * EDIT: Sorry, I meant to post this in the hacks sub-forum, can a mod move it please?

The topic ‘Adding custom login authentication’ is closed to new replies.

## Tags

 * [authentication](https://wordpress.org/support/topic-tag/authentication/)
 * [login](https://wordpress.org/support/topic-tag/login/)
 * [wp_authenticate](https://wordpress.org/support/topic-tag/wp_authenticate/)
 * [wp_login](https://wordpress.org/support/topic-tag/wp_login/)

 * 0 replies
 * 1 participant
 * Last reply from: [JazzyP](https://wordpress.org/support/users/jpiionefourone/)
 * Last activity: [12 years ago](https://wordpress.org/support/topic/adding-custom-login-authentication/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
