Site icon Hip-Hop Website Design and Development

Validate user login in php

Hey guys so I made a custom API for my wordpress site and i need to check if the username and passord is correct. I did it with the following code but its not working since it always returns "valid" because i myself am logged in.

I need to be logged in to access my api but also need to check if the account of another user is valid by checking username and password.

The API is used to also link a xenforo account as example with my wordpress site.

This is the code i came up with which is not 100% correct.

function checkLogin($user, $pass){
    $creds = array();
    $creds['user_login'] = $user;
    $creds['user_password'] = $pass;
    $creds['remember'] = true;

    $user = wp_signon( $creds, false );

    if ( is_wp_error($user) ) {
        //echo $user->get_error_message();
        respond("account-creds-invalid");
    }
    else {
        respond("account-creds-valid");
    }

}