We are trying to clear the code of custom login with authentication. here we have the code.
// Authentication of username and password..
$uid = \Drupal::service('user.auth')->authenticate($username,$password);
// Get the user id by database and load..
$user = \Drupal\user\Entity\User::load($uid);
// finally pass the user detail array in user login function..
user_login_finalize($user);
Example:
Like we have username and password by POST method and fields are.
<input id="login-username" type="text" class="form-control" name="name" value="" placeholder="username">
<input id="login-password" type="password" class="form-control" name="pass" placeholder="password">
so for got these credentials in function the code is.
$username = \Drupal::request()->request->get('name'); // form username
$password = \Drupal::request()->request->get('pass'); // form password
And the final code for login..
$uid = \Drupal::service('user.auth')->authenticate($username,$password);
$user = \Drupal\user\Entity\User::load($uid);
user_login_finalize($user);
Note: If have any suggestions or issue regarding 'Custom login create in drupal 8' then you can ask by comments.
// Authentication of username and password..
$uid = \Drupal::service('user.auth')->authenticate($username,$password);
// Get the user id by database and load..
$user = \Drupal\user\Entity\User::load($uid);
// finally pass the user detail array in user login function..
user_login_finalize($user);
Example:
Like we have username and password by POST method and fields are.
<input id="login-username" type="text" class="form-control" name="name" value="" placeholder="username">
<input id="login-password" type="password" class="form-control" name="pass" placeholder="password">
so for got these credentials in function the code is.
$username = \Drupal::request()->request->get('name'); // form username
$password = \Drupal::request()->request->get('pass'); // form password
And the final code for login..
$uid = \Drupal::service('user.auth')->authenticate($username,$password);
$user = \Drupal\user\Entity\User::load($uid);
user_login_finalize($user);
Note: If have any suggestions or issue regarding 'Custom login create in drupal 8' then you can ask by comments.
user_login_finalize make user logged-in but page header are not updated
ReplyDelete