I am trying to remove "Reset your Password" on the login screen in Drupal 8. Any ideas?

PS: I'm not great at php and I have adaptivetheme as my theme

Thanks,
James

Comments

hiramanpatil’s picture

You can try the solution given at https://gist.github.com/zviryatko/37c01dcd2e24ae1674f7

Thanks,

theicecreamman22’s picture

Thanks for that link. I have been looking for something like that. But, how do I use it. Where does it go?

hiramanpatil’s picture

You need to create one custom module for this. Search for 'how to create custom module in drupal 8'.

Thanks,

theicecreamman22’s picture

It works :)

golubovicm’s picture

use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_form_alter().
 */
function YOUR_MODULE_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if (($form_id == 'user_login_block' || $form_id == 'user_login_form')) {
    if (isset($form['more-links']['forgot_password_link'])) {
      unset ($form['more-links']['forgot_password_link']);
    }
  }
}
Have in mind that just removing that link won't disable password forgot page. To do that I created route subscriber and registered it as service (file name "RouteSubscriber.php", placed in "src" dir of YOU_MODULE). Make sure to have correct names spaces:
<?php

namespace Drupal\your_module;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

/**
 * Listens to the dynamic route events.
 */
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  public function alterRoutes(RouteCollection $collection) {
    // Always deny access to '/user/password'.
    if ($route = $collection->get('user.pass')) {
      $route->setRequirement('_access', 'FALSE');
    }
    if ($route = $collection->get('user.pass.http')) {
      $route->setRequirement('_access', 'FALSE');
    }
  }

}

And registered it as service in your_module.services.yml file:

services:
  your_module.route_subscriber:
    class: Drupal\your_module\RouteSubscriber
    tags:
      - { name: event_subscriber }