Title: Authenticate user on custom endpoint
Last modified: August 31, 2016

---

# Authenticate user on custom endpoint

 *  [pathardepavan](https://wordpress.org/support/users/pathardepavan/)
 * (@pathardepavan)
 * [10 years ago](https://wordpress.org/support/topic/authenticate-user-on-custom-endpoint/)
 * Hi All,
 * I have created a new endpoint for authenticating user using basic authentication.
   The client will send headers like
    Authorization Basic <base64 encoded token>
 * When i send right username and password function works fine . But when i give
   wrong password there is no response.
 * Please find the code for function below
 *     ```
       function check_authentication( WP_REST_Request $request ) {
   
           $serverparams = apache_request_headers();
           $authorization = $serverparams['Authorization'];
   
           if($authorization!='')
           {
               $authvalues = explode(' ',$authorization);
               $usernamepass = $authvalues[1];
               $usernamepassdecode = base64_decode($usernamepass);
               $creds = explode(':',$usernamepassdecode);
               $username = $creds[0];
               echo $username;
   
               $pass = $creds[1];
               echo $pass;
               $user = get_user_by('login',$username);
               if(wp_check_password($pass,$user->user_pass,$user->ID))
                   return 'Success';
               else
                   return 'Fail';
   
           }
           else{
               return 'authorization header missing';
           }
   
       }
       ```
   
 * can some one please help me here ?
 * Thanks,
    Pavan
 * [https://wordpress.org/plugins/json-rest-api/](https://wordpress.org/plugins/json-rest-api/)

The topic ‘Authenticate user on custom endpoint’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/json-rest-api_2e3641.svg)
 * [WP REST API (WP API)](https://wordpress.org/plugins/json-rest-api/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/json-rest-api/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/json-rest-api/)
 * [Active Topics](https://wordpress.org/support/plugin/json-rest-api/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/json-rest-api/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/json-rest-api/reviews/)

## Tags

 * [authentication](https://wordpress.org/support/topic-tag/authentication/)
 * [wp rest api](https://wordpress.org/support/topic-tag/wp-rest-api/)

 * 0 replies
 * 1 participant
 * Last reply from: [pathardepavan](https://wordpress.org/support/users/pathardepavan/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/authenticate-user-on-custom-endpoint/)
 * Status: not resolved