Simple Membership Plugin › Forums › Simple Membership Plugin › How to use the REST query to verify a member?
- This topic has 4 replies, 2 voices, and was last updated 3 years, 7 months ago by
Stefan.
-
AuthorPosts
-
April 16, 2023 at 4:46 pm #25956
Stefan
ParticipantHi all,
I have a very simple question. With the simple REST API I can query all a users credentials. I just want to write a simple script which processes username and password from the outside, checking if they are valid, so I thought I could generate a hash from the plain password and compare it with the password of the query. Unfortunately I cannot find a way to produce the same hash as in the query on my server using PHP.
I have already seen that someone pointed out to the WordPress docs about the password hashing methods. But these don’t work as expected – they produce a different hash with each call, and none of them compares to the one of the query. Any hint would be appreciated.
April 16, 2023 at 8:07 pm #25957Stefan
ParticipantIt comes down to the question what exactly the password (hash) in the query result is coming from.
If I take a random password, hash it with wp_create_password() and immediately check it with wp_check_password(), the result is true. So far, so good 🙂
If I create a new user with the password “123456789”, the query produces a result. If I check that with wp_check_password(), the result is false.
So far I see two possible reasons:
1. The passwords by Simple Membership haven’t been created on the column “password” but on something else…
2. The passwords by Simple Membership haven’t been created by a wp_create_password() call…
3. The code behind wp_check_password() in my test environment is not the same as used in my WordPress installation (unlikely since this framework code hasn’t been the subject to changes for a long time).
Any ideas?
April 17, 2023 at 12:18 am #25960The Assurer
ModeratorThe SWPM passwords are hashed using public static function encrypt_password( $plain_password ) in the class.swpm-utils.php file.
April 17, 2023 at 7:58 am #25962Stefan
ParticipantThank you – but I don’t suppose so. The code there is identical with the wp_create_hash()-example (using HashPassword() of a PasswordHash instance with (8,true) – and it produces something different from the password field of the query result.
April 17, 2023 at 8:56 am #25963Stefan
Participant[Solved] The problems were added backslashes in the query result, so it didn’t match the database content. Processing the result through stripslashes() did the job. Thanks again.
-
AuthorPosts
- You must be logged in to reply to this topic.