Drupal - Creating an alternative login page other than /user/login

Yes, your code is complete, and is as safe as the default login form.

However, do bear in mind that if you want to replace the /user/login form, you will need to think about all scenarios in which users might end up there (e.g. [site:login-url] token, other modules, etc.) and handle them appropriately via redirects or access denied response (e.g. if you will be the only registered user on the site).

Here are the basics:

Redirecting

If you want to redirect users from /user/login to /authenticate for whatever reason, you will either need to use the Redirect module, or implement hook_menu_alter() in your custom module:

function YOUR_MODULE_menu_alter(&$items) {
  $items['user/login']['page callback'] = 'drupal_goto';
  $items['user/login']['page arguments'] = 'authenticate';
}

Replacing

If you want to make /user/login inaccessible to all other users, you can simply disable that path by again implementing the hook_menu_alter() in your custom module:

function YOUR_MODULE_menu_alter(&$items) {
  $items['user/login']['access callback'] = FALSE;
}

However, do bear in mind that you will have to test everything thoroughly and make sure that you have no modules that depend on the system /user/login, as well as that there are no workflows that will be affected (e.g. [site:login-url] tokens).

Hope this helps.

Tags:

Forms

Users

7