Closed sponi78 closed 4 months ago
As far as I know, there is no explicit method that can test both the username and password of a user. But you can simply try to generate a JWT token with your credentials and if it generates a valid token, then a user with the given credentials exists.
You can simply do:
var client = new WordPressClient(ApiCredentials.WordPressUri);
client.AuthMethod = AuthMethod.JWT;
await client.RequestJWToken(ApiCredentials.Username,ApiCredentials.Password);
// check if authentication has been successful
var isValidToken = await client.IsValidJWToken();
and if isValidToken
is true then the user with the credentials exists.
I've been using the Get Current User method to accomplish this: https://wp-net.github.io/WordPressPCL/I%20version%202.x/entities/users/
If the submitted username/password does not work, the method will throw an exception. If if does match, then a User
object is returned.
Is there a way to check if a user with a give username and password exists?