Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By damiankloip on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Introduced in version:
8.x
Description:
The procedural user_authenticate() has now been deprecated in favour of using a 'user.auth' service (UserAuth object).
Before:
$form_state['uid'] = user_authenticate($form_state['values']['name'], $password);
Now:
// Inject user.auth service..
$form_state['uid'] = $this->userAuth->authenticate($form_state['values']['name'], $password);
// or
$form_state['uid'] = \Drupal::service('user.auth')->authenticate($form_state['values']['name'], $password);
Impacts:
Module developers
Comments
$form_state is now also an
$form_state is now also an object.
User not signing in
Hi guys, I'm migrating some old code from D6 to D8 but unfortunately, facing some trouble with this guide. Previously I had this:
user_authenticate($userRequest)
Now I changed it per @damiankloip 's suggestion to:
\Drupal::service('user.auth')->authenticate($userRequest['name'],$userRequest['pass']);
It runs perfect and returns the user id OK, the problem is that after finishing the execution, the user is still logged out. ..
Can you help me figuring out what am I missing?
Thanks in advance
Solved !
After digging in, I found the solution:
The first line returns the
user_id
, then it is needed to create the entity and call theuser_login_finalize
function like this:Hope this helps someone else, cheers!