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.
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')]));
}
}
devel
and enablekint
module. Instead ofecho $form_state...
putkint(xdebug_get_function_stack());
orkint(debug_backtrace())
if you don't have xdebug installed. This should show you where the data has passed through to come intovalidateName
. 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.