0

Recently I got in to an issue that I can't login to the system. I tried to clear the cache and reviewed all the permissions. I logged in via one time password url created by drush uli and then changed the admin password and then tried to login . Still no luck. Even when I created a new user/modified the password of existing user and tried to login, still login not working.

I tried the same scenario in an incognito window too and not working.

I have another server in the same network with the same admin and users, and with same permissions. It is working with no issues.

I had a database backup from earlier, when I restored the db first time the login is working. But then after logout it's not working.

Is it related to some caching or permission issue? If someone can give any insights it will be great.

enter image description here

When I checked in to the core module (user) and not getting the username in the validateName validate function , but am getting the password though. Any idea of this strange behaviour ?

in UserLoginForm.php

/**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this->config('system.site');

    // Display login form:
    $form['name'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Username'),
      '#size' => 60,
      '#maxlength' => USERNAME_MAX_LENGTH,
      '#description' => $this->t('Enter your @s username.', ['@s' => $config->get('name')]),
      '#required' => TRUE,
      '#attributes' => [
        'autocorrect' => 'none',
        'autocapitalize' => 'none',
        'spellcheck' => 'false',
        'autofocus' => 'autofocus',
      ],
    ];

    $form['pass'] = [
      '#type' => 'password',
      '#title' => $this->t('Password'),
      '#size' => 60,
      '#description' => $this->t('Enter the password that accompanies your username.'),
      '#required' => TRUE,
    ];

    $form['actions'] = ['#type' => 'actions'];
    $form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->t('Log in')];

    $form['#validate'][] = '::validateName';
    $form['#validate'][] = '::validateAuthentication';
    $form['#validate'][] = '::validateFinal';

    $this->renderer->addCacheableDependency($form, $config);

    return $form;
  }

    /**
       * Sets an error if supplied username has been blocked.
       */
      public function validateName(array &$form, FormStateInterface $form_state) { 
echo $form_state->getValue('name');exit; //not getting this though
        if (!$form_state->isValueEmpty('name') && user_is_blocked($form_state->getValue('name'))) {
          // Blocked in user administration.
          $form_state->setErrorByName('name', $this->t('The username %name has not been activated or is blocked.', ['%name' => $form_state->getValue('name')]));
        }
      }
11
  • 1
    Can you exclude the possibility that your server is hacked?
    – Justme
    May 3, 2018 at 11:01
  • 1
    What is the behavior if you make a copy of the webroot folder and db from the system which it is not working to your local system ? Only edit the setting.php for the mysql connectie ... not else...
    – Justme
    May 3, 2018 at 11:12
  • 1
    Install devel and enable kint module. Instead of echo $form_state... put kint(xdebug_get_function_stack()); or kint(debug_backtrace()) if you don't have xdebug installed. This should show you where the data has passed through to come into validateName. Try to trace it from there and see where the username is going missing. Also have you tried extracting a fresh Drupal 8.4.4 on top of your site or rebuilding it? It could be that the core files were accidentally modified if you use Composer led build. Or it could (unlikely) be corrupt {sessions} table. Too broad to answer really.
    – Beebee
    May 3, 2018 at 12:52
  • 1
    @RubberDuckIsKing Please stop using code formatting for things that aren't code; the excessive use of bold/strong text isn't needed either, the question reads fine without it. Thanks!
    – Clive
    May 3, 2018 at 13:15
  • 1
    Is there some sort of cookie domain or whatever set? That used to cause this for me in Drupal 7.
    – Kevin
    May 3, 2018 at 13:29

0

Your Answer

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

Browse other questions tagged or ask your own question.