Creating a custom login system by developing a new module I've created 2 files: 


login_process.info
login_process.module


I've created the table "user" in the database that Drupal is using. I want to display a custom login form with fields "Username" and "Password". 

Assuming the data from Username and Password fields are in the correct format(proper validations), when the submit button is pressed, a query is done and data to check if the values matches that found in the table. 

If no result is found, it displays an error message

else it redirects to to the welcome page.


Here are the codes:

login_process.info

name = "My login process module"
description = "Performs login process" 
core = "7.x"
version ="7.x.1.0"
package = "Login/Register"`


login_process.module

&lt;?php

/*
*Implements hook permission
*/


function login_process_hook_permission() 
{
 return array(
    'submit login_process' =&gt; array(
      'title' =&gt; t('Submit login form'),
      'description' =&gt; t('Submit the login form')
    ),
  );
}

/* 
* Implements hook menu
*/

function login_process_hook_menu() {
  $items = array();
    $items['login-process'] = array(
  'title' =&gt; 'login',
  'type' =&gt; 'MENU_NORMAL_ITEM',
  'access arguments' =&gt; array('submit login_process'),
    'page callback' =&gt; 'drupal_get_form',   
    'page arguments' =&gt; array('login_process_form')
    );
    return $items;
}

/*
* The login form
*/

function login_process_form($form,&amp;$form_state)
{
  $form['Username'] = array(
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('Username'),
  '#size' =&gt; 20,
  '#maxlength' =&gt; 20,
  '#required' =&gt; TRUE,
  '#description' =&gt; t('Please enter a valid username'),
  );

  $form['Password'] = array(
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('Password'),
  '#size' =&gt; 20,
  '#maxlength' =&gt; 20,
  '#required' =&gt; TRUE,
  '#description' =&gt; t('Please enter a valid password'),
  );
  $form['submit'] = array(
  '#type' =&gt; 'submit',
  '#value' =&gt; t('Add item')

  );
  return $form;
}
/*
* Validation handler for the login_process_form
*/

function login_process_form_validate($form,&amp;$form_state)
{
  print('&lt;pre&gt;'.print_r($form_state['values'],1).'&lt;pre&gt;'); die();
  if (!preg_match("/[a-zA-Z]/",$form_state['values']['Username'])) 
  {
    form_set_error('Username', t('Username must contain only alphabets'));
    return FALSE;
  }
  return TRUE;
  //add more validations for Username and Password
}

/*
*Submit handler for the login form
*/

function login_process_form_submit($form,&amp;$form_states)
{

  $username = $form_state['values']['Username'];
  $password =  $form_state['values']['Password'];
  $results = db_query("SELECT Username,Password FROM user WHERE Username='".$username."' AND Password='".$password."'"));
  if(is_null($results))
  {
    form_set_error('Username', t('Wrong username or password. Try again!!!!'));
    return FALSE;
  }
  else
  {
  echo "Welcome".$form_state['values']['Username']."&lt;a href="logout.php"&gt;Logout&lt;/a&gt;" // it will be better if it is displayed in a block
  }
}


It neither display errors nor the login form created from the module. Can anyone help me here? Do I have to install additional modules to make it work?

Most of the codes are based from Daily dose of Drupal episode 16 to 22.
You don't need any other modules, to just show a form. Your code is not correct in some points, though, and that needs to be corrected.

A form validation handler doesn't return TRUE nor FALSE; it just calls form_set_error() in case the submitted data doesn't pass the validation.

A form submission handler doesn't validate the submitted data; that is the task of the form validation handlers. The purpose of the form submission handlers is to take the necessary actions (e.g. loading data from the database, saving data to the database), but they don't return anything.

You don't inject values entered from user directly in the query, as you do with db_query(). That is the perfect way of given a malicious user access to the user #1 access, for example, and without the user knowing the user #1 account.
Always use placeholders for input obtained from users, when you are using it in a query. See what user_login_authenticate_validate() does.

$account = db_query("SELECT * FROM {users} WHERE name = :name AND status = 1", array(':name' =&gt; $form_state['values']['name']))-&gt;fetchObject();


The correct way to show a message to the user is using drupal_set_message(). In the specific case, showing a message with a logout link is not much helpful, since the users will not see it anymore after moving to a different page. In any case, you don't use echo() to print anything on a Drupal page from a form submission (or validation) handler.