title: How can I login to HTML login page with my email address in Django
body: <p>I create a HTML login page and I authenticate it through <code>views.py</code>. I want to login with my email address only. But when I use other email addresses , I can able to login.I set custom_authentication in my <code>views.py</code>. </p>
  
  <p>Template login.html</p>
  
  <pre><code>{% load staticfiles %}
  
  
  &lt;!DOCTYPE html&gt;
  &lt;!--[if lt IE 7]&gt; &lt;html class="lt-ie9 lt-ie8 lt-ie7" lang="en"&gt; &lt;![endif]--&gt;
  &lt;!--[if IE 7]&gt; &lt;html class="lt-ie9 lt-ie8" lang="en"&gt; &lt;![endif]--&gt;
  &lt;!--[if IE 8]&gt; &lt;html class="lt-ie9" lang="en"&gt; &lt;![endif]--&gt;
  &lt;!--[if gt IE 8]&gt;&lt;!--&gt; &lt;html lang="en"&gt; &lt;!--&lt;![endif]--&gt;
  &lt;head&gt;
  &lt;title&gt;S.P.M School&lt;/title&gt;
  
   &lt;link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"&gt;
          &lt;link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"&gt;
          &lt;link rel="stylesheet" href="{% static 'css/style.css' %}"&gt;
          &lt;link href="//fonts.googleapis.com/css?family=Lobster&amp;subset=latin,latin-ext" rel="stylesheet" type="text/css"&gt;
  
            &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
    &lt;link rel="stylesheet"
  href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"&gt;
    &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"&gt;&lt;/script&gt;
    &lt;script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"&gt;&lt;/script&gt;
  
  
    &lt;meta charset="utf-8"&gt;
    &lt;meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"&gt;
  
    &lt;link rel="stylesheet" href="css/style.css"&gt;
    &lt;!--[if lt IE 9]&gt;&lt;script src="//html5shim.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt;&lt;![endif]--&gt;
  &lt;style&gt;
  table, th, td {
      border: 0px solid black;
  }
  &lt;/style&gt;
  &lt;script&gt;
  function validateForm() {
      var mail = document.forms["myForm"]["email"].value;
  var psd = document.forms["myForm"]["password"].value;
      var atpos = mail.indexOf("@");
      var dotpos = mail.lastIndexOf(".");
      if (atpos&lt;1 || dotpos&lt;atpos+2 || dotpos+2&gt;=mail.length) {
          alert("Not a valid e-mail address");
          return false;
  
     }
  if (psd == null || psd == "") {
          alert("Not a valid Password");
          return false;
      }
  
  }
  
  
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
   &lt;div id="page"&gt;
    &lt;div id="header"&gt;
      &lt;div id="section"&gt;
  
   {% if user.is_authenticated %}
  &lt;a href="{% url 'post_new' %}" class="top-menu"&gt;&lt;span class="glyphicon glyphicon-plus"&gt;&lt;/span&gt;&lt;/a&gt;
  {% endif %}
  
        &lt;div class="headline"&gt;
        &lt;font size="10": color="white"&gt;&lt;center&gt;S.P.M.L.P School&lt;/center&gt;&lt;/font&gt;
        &lt;/div&gt;
  
  
        &lt;span&gt;303nishanth@gmail.com &lt;br /&gt;
        &lt;br /&gt;
        +91 9961685892&lt;/span&gt; &lt;/div&gt;
  
      &lt;ul&gt;
        &lt;li class="#"&gt;&lt;a href="/"&gt;Home&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="{% url 'about' %}"&gt;About Us&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="{% url 'event' %}"&gt;Event&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="{% url 'calendar' %}"&gt;School Calendar&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="{% url 'contact' %}"&gt;Contact us&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
  
  &lt;br&gt;&lt;br&gt;
    &lt;section class="container"&gt;
      &lt;div class="login"&gt;
  
  
      &lt;div id="section"&gt;&lt;br&gt;&lt;br&gt;
        &lt;h1&gt;&lt;center&gt;Login As&lt;font color="red"&gt; Admin&lt;/font&gt;&lt;/center&gt;&lt;/h1&gt;&lt;br&gt;
         &lt;/div&gt;
  
           &lt;form name="myForm" action="{% url 'class_info' %}" onsubmit="return validateForm();" method="post"&gt;
  
  
  
  
          &lt;input type='hidden' name='csrfmiddlewaretoken' value='wu5eSIDElr8EsVDgXmHmFNCCmSLdhyK5' /&gt;
           {%csrf_token%}
  
  
       &lt;div class="text"&gt;
          &lt;p&gt;&lt;center&gt;&lt;input type="text" name="email"  placeholder="Username or Email"&gt;&lt;/p&gt;&lt;/center&gt;
          &lt;p&gt;&lt;center&gt;&lt;input type="password" name="password" placeholder="Password"&gt;&lt;/p&gt;&lt;/center&gt;
          &lt;p class="remember_me"&gt;
  
  
  
  
          &lt;/p&gt;
          &lt;center&gt;&lt;p class="submit"&gt;&lt;input type="submit" name="commit" value="Login"&gt;&lt;/p&gt;&lt;/center&gt;
        &lt;/form&gt;
      &lt;/div&gt;
  
  
    &lt;/section&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>def login(request):
      return render(request, 'blog/login.html')
  
  def custom_auth(username=None, password=None):
      user = None
      if username == '303nishanth@gmail.com': # only this email is allowed
         user = authenticate(username=email, password=psd)
      return user
  
  def login_submit(request):
      context = {}
  
      email = request.POST.get('email','')
      psd = request.POST.get('password', '')
  
      user = custom_auth(username=email, password=psd)
      if user is not None:
          # the password verified for the user
              if user.is_active:
                  context['message'] = "User is valid, active and authenticated"
                  return render (request,'class_info.html',context)   
              else:
                      context['message']= "The password is valid, but the account has been disabled!"
      else:
          # the authentication system was unable to verify the username and password
              context['message']= "The username and password were incorrect."
  
      return render (request,'login.html',context)
  </code></pre>