xml rpc – Retrieve username and password from XMLRPC request

Question

I’m working on a plugin to log the username and password sent as part of an XMLRPC payload. I have previously got this working by capturing the raw data packet with the full XML payload via file_get_contents("php://input"), however ideally I just need the username and login provided.

I’m looking to build something similar to https://wordpress.org/plugins/wp-login-attempt-log/, which tracks failed login attempts for wp-login.php.

During my research I found a snippet to authenticate external requests through XMLRPC (https://gist.github.com/chrisguitarguy/1653264) however modifying the above snippet to write to a file from a plugin has not worked:

add_filter('xmlrpc_methods', 'wpse39662_add_login_method' );
function wpse39662_add_login_method( $methods )
{
    $methods['wpse39662.login'] = 'wpse39662_check_login';
    return $methods;
}

function wpse39662_check_login( $args )
{
    $username = $args[0];
    $password = $args[1];
    $myfile = fopen('xmlrpc.txt', 'w') or die('Unable to open file');
    fwrite($myfile, $username);
    fwrite($myfile, $password);
    fclose($myfile);
}

For now I’m just testing the arguments/variables using fwrite() but in the long run planning to write this to the database.

Any pointers would be much appreciated!

0
johnamq 7 days 2023-03-15T21:48:27-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse