0

I created in my plugin a wp_authenticate function:

if ( ! function_exists( 'wp_authenticate' ) ) :
     function wp_authenticate( $username, $password )
     {

inside this function, if it's the first login I change the password stored in the database (I do this because the password was saved after a data porting from a Magento site, so it needs to be updated with wp_hash_password()).

If you are logged in from the page

/wp-login.php

the password is updated, but the login is not performed. The login works from the next attempt.

If instead the login is performed from the page

/my_account

everything works fine from the first attempt.

Because?

2
  • 1
    wp_authenticate is already a function in WordPress, I'm guessing you're trying to use a pluggable function? Pluggable functions are a very very old WordPress feature that predate the hooks/actions/filters system which people use today. This is not how it is done today. You would be much better off with the developer.wordpress.org/reference/hooks/wp_authenticate hook which is more compatible and easier to use than what you've done. The doc I linked to also has user contributed examples of custom authentication
    – Tom J Nowell
    Jan 19, 2023 at 14:52
  • Yes, you are right, pluggabe function is old. I tried with a hook initially, but the problem was the same.
    – Infocurci
    Jan 20, 2023 at 14:13

1 Answer 1

0

I found the problem, the login procedure pre-loads the USER object in cache.

The password that is checked is always the initial one: changing the password in the database only works from the next login attempt. I fixed it by adding

clean_user_cache($userId)

But I don't understand why if I try to login from the "my account" page, the user cache is not considered.

Maybe it's because of the absence of the "remember me?" flag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.