• About Me
  • My Portfolio
  • Blog
    • PHP
    • WORDPRESS
    • Laravel
    • Code Snippets
    • NodeJs
    • ReactJs
  • Contact Me
  • Hire Me On Upwork

Narinder Singh

Web Developer

Code Snippets Drupal

Drupal error message “unrecognized username or password” When Attempting Login

By Narinder Bisht on Tuesday, April 13, 2021

This blog post information will help in the drupal login attempt failure. This issue generally comes, if you shift your drupal setup from local to live server or shift from one server to another server.
You need to place the following code snippet into this file path.

File Path: DRUPALROOT\core\modules\user\src\UserAuth.php

Function Name: authenticate($username, $password)

1. Code Snippet

echo $password; 
echo '<br/>';
echo $this->passwordChecker->needsRehash($password);
echo '<br/>';
$account->setPassword($password);
$account->save();
echo $this->passwordChecker->check($password, $account->getPassword());
die();

2. Full Function Code


public function authenticate($username, $password) {
    $uid = FALSE;

    if (!empty($username) && strlen($password) > 0) {
      $account_search = $this->entityTypeManager->getStorage('user')->loadByProperties(['name' => $username]);
	  
	if ($account = reset($account_search)) {
        if ($this->passwordChecker->check($password, $account->getPassword())) {
          // Successful authentication.
          $uid = $account->id();

          // Update user to new password scheme if needed.
          if ($this->passwordChecker->needsRehash($account->getPassword())) {
            $account->setPassword($password);
            $account->save();
          }
        }
      }
	  //echo $password, $account->getPassword(); 
		echo $this->passwordChecker->needsRehash($password);
		$account->setPassword($password);
		$account->save();
		echo $this->passwordChecker->check($password, $account->getPassword());
		die();
    }

    return $uid;
  }

This code snippet will re-hash your current password. After one attempt you need to remove the extra code from the function and re-upload the file.

Then try your drupal login. Drupal login issue will fix.

Note: Before trying this code, you must know what you are doing, if you are not a PHP programmer, please ignore this. One more thing, before trying this code, you must sure that your username is existing in the database.

drupal login
0
Previous Post
Next Post
Related Posts
Code Snippets

How to fix DNS_PROBE_FINISHED_NXDOMAIN issue on chrome? If website is working fine with VPN extension.

Code Snippets WordPress

How to Customizing Email Templates, Subjects and add content dynamically?

Country phone field contact form 7
Code Snippets PHP WordPress

The country code drop-down list doesn’t appear in the Elementor popup (country & phone field contact form 7)

About Me
Narinder Singh Bisht
Narinder Singh Bisht

Web Developer & Blogger

Hire me on Upwork
Narinder Upwork Profile
PDF Plugin
SeoBuddy
Recent Posts
  • Automate the Calendly and MailerLite integration to sync the event subscriber data with MailerLite into a specific group
  • How to fix DNS_PROBE_FINISHED_NXDOMAIN issue on chrome? If website is working fine with VPN extension.
  • How to Customizing Email Templates, Subjects and add content dynamically?
  • Can’t import reviews from CSV files- Customer Reviews for WooCommerce
  • The country code drop-down list doesn’t appear in the Elementor popup (country & phone field contact form 7)
Categories
  • API
  • Code Snippets
  • CSS
  • Drupal
  • HTML
  • Laravel
  • Magento
  • NodeJs
  • PHP
  • ReactJs
  • WooCommerce
  • WordPress
Theme by Scissor Themes Proudly powered by WordPress