Евгений
Евгений

Reputation: 49

How to make a password reset request in wordpress

I'm trying to use postman to make a post request to reset the password, to the wordpress site. Here is what query is obtained as a result: https://example.com/wp-login.php?action=lostpassword&user_login=User123

And in the end I get the answer: ERROR: Enter a username or email address. How to make a request correctly and is it even possible?

enter image description here

Upvotes: 2

Views: 2192

Answers (1)

Myo Win
Myo Win

Reputation: 533

I got it!

What OP did wrong was sending the user_login value in Postman's Params instead of form-data or x-www-form-urlencoded.

Here is the working Postman request

The success response contains "Check your email" as title until WordPress change that

But that's not all. I am using Flutter for developing my mobile app and http package to send the request and the normal http.post() won't work. It only works with MultipartRequest for some reason.

Here is the full working request for Flutter's http package.

String url = "https://www.yourdomain.com/wp-login.php?action=lostpassword";

Map<String, String> headers = {
  'Content-Type': 'multipart/form-data; charset=UTF-8',
  'Accept': 'application/json',
};

Map<String, String> body = {
  'user_login': userLogin
};

var request = http.MultipartRequest('POST', Uri.parse(url))
  ..fields.addAll(body)
  ..headers.addAll(headers);

var response = await request.send();

// forgot password link redirect on success
if ([
  200,
  302
].contains(response.statusCode)) {
  return 'success';
} else {
  print(response.statusCode);
  throw Exception('Failed to send. Please try again later.');
}

Upvotes: 5

Related Questions