title: Login page issue (flask ,python)
body: <p>I'm pretty much new to Python and Flask and trying to create website with user registration and user login.</p>
  <p>I'm able to create users using Registration page but i'm unable to login using same user credential which were used during user registration.</p>
  <p>Below is the code that i have written</p>
  <pre><code>from flask import Flask, render_template, request, flash, redirect, url_for,session
  import os
  from flask_sqlalchemy import SQLAlchemy
  from app import db
  from werkzeug.security import generate_password_hash,check_password_hash
  
  #from flaskr.db import get_db
  #import pdb; pdb.set_trace()
  
  app = Flask(__name__)
  app.secret_key = os.urandom(24)
  
  
  app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://support:support@rea-lnx-tdin01:5432/postgres'
  db = SQLAlchemy(app)
  
  
  @app.route('/', methods=[&quot;GET&quot;, &quot;POST&quot;])
  def registration():
      Specialsym =['$','@','#']
      from models import name
      if request.method == &quot;POST&quot;:
          username = request.form.get('Username')
          password = request.form.get('Password')
          conf_password = request.form.get('RepeatPassword')
          error = None
          if not username:
              error = 'Username is required'
              flash(error)
          elif not password:
              error = 'Password is required'
              flash(error)
          elif len(username)&lt; 4:
              error = &quot;User Name should be of minimum of 4 characters&quot;
              flash(error)
          elif len(username)&gt; 12:
              error = &quot;User Name should be of maximum of 8 characters&quot;
              flash(error)
          elif len(password)&lt; 6:
              error = &quot;Password should be of minimum of six characters&quot;
              flash(error)
          elif len(password) &gt; 8:
              error = &quot;Password should be of maximum of eight characters&quot;
              flash(error)
          elif not any(char.isupper() for char in password):
              error = &quot;Password should have at least upper case letter&quot;
              flash(error)
          elif not any(char.isdigit() for char in password):
              error = &quot;Password should have at least one digit&quot;
              flash(error)
          elif not any(char.islower() for char in password):
              error = &quot;Password should have at least one lower case letter&quot;
              flash(error)
          elif not any(char in Specialsym for char in password):
              error =&quot;Password should have at least one of the symbols $ @ # &quot;
              flash(error)
          elif name.query.filter_by(username=username).first() is not None:
              error = 'User  is already registered'
              flash(error)
          elif password != conf_password:
              error = 'Passwords Must Match'
             # pass_1 = password
              #pass_2 = request.form.get('RepeatPassword')
              flash(error)
              #flash(pass_1)
              #flash(pass_2)
          elif error is None:
              user = name(username=username, password=generate_password_hash(password))
              db.session.add(user)
              db.session.commit()
              flash(&quot; User Created successfully &quot;)
  
          #return redirect(url_for('login_page'))
      return render_template('Esp_Index.html')
  
  
  @app.route('/loginpage/', methods=[&quot;GET&quot;, &quot;POST&quot;])
  def login():
      return render_template('Loginpage.html')
  
  
  @app.route('/Fulfilment/', methods=[&quot;GET&quot;, &quot;POST&quot;])
  def fulfil():
     return render_template('Ful_Product_Provider.html')
  
  
  @app.route('/login/', methods=[&quot;GET&quot;, &quot;POST&quot;])
  def login_page():
      from models import name
      if request.method == 'POST':
          username = request.form.get('Username')
          password = request.form.get('Password')
          flash(username)
          error = None
  
          user = name.query.filter_by(username=username).first()
          if user is None:
              error = &quot;User Name doesn't Exist or it's Invalid!!&quot;
              flash(error)
              flash(user)
          elif not check_password_hash(user['password'], password):
              error = &quot;Incorrect Password&quot;
              flash(error)
          if error is None:
              session.clear()
              session['user_id'] = user['id']
              return redirect(url_for('fulfil.html'))
  
              #flash(error)
      return render_template('Loginpage.html')
  </code></pre>
  Jinja code####
  <h3>ESP_Base.html</h3>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
      {% block head %}
      &lt;title&gt;{% block title %}{% endblock %}&lt;/title&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
      &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
      &lt;script type=&quot;application/x-javascript&quot;&gt; addEventListener(&quot;load&quot;, function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } &lt;/script &gt;
    &lt;!-- Custom Theme files --&gt;
      &lt;link href=&quot;{{url_for('static',filename='css/Styles.css')}}&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;all&quot; /&gt;
      &lt;!-- //Custom Theme files --&gt;
      &lt;link href=&quot;//fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i&quot; rel=&quot;stylesheet&quot;&gt;    &lt;!-- //web font --&gt;
      {% endblock %}
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id=&quot;content&quot; &gt;{% block content %}
  
          {% endblock %}&lt;/div&gt;
              &lt;ul class=&quot;colorlib-bubbles&quot;&gt;
              &lt;li&gt;&lt;/li&gt;
              &lt;li&gt;&lt;/li&gt;
              &lt;li&gt;&lt;/li&gt;
              &lt;li&gt;&lt;/li&gt;
              &lt;li&gt;&lt;/li&gt;
              &lt;li&gt;&lt;/li&gt;
              &lt;li&gt;&lt;/li&gt;
              &lt;li&gt;&lt;/li&gt;
              &lt;li&gt;&lt;/li&gt;
              &lt;li&gt;&lt;/li&gt;
          &lt;/ul&gt;
  
  &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js&quot;&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  Index.html#########
  <pre><code> {% extends &quot;ESP_Base.html&quot; %}
      {% block title %}Enterprise App Support Console{% endblock %}
      {% block head %}
        {{ super() }}
      {% endblock %}
      {% block body %}
      {% block content %}
       &lt;h1&gt;Enterprise Appsupport SignUp Portal Form&lt;/h1&gt;
      {% with errors = get_flashed_messages() %}
           {% if errors %}
             {% for error in errors %}
              &lt;div class=&quot;alert alert-warning alert-dismissible fade show&quot; role=&quot;alert&quot;&gt;
                      &lt;strong&gt;{{ error }}&lt;/strong&gt;
                      &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;alert&quot; aria-label=&quot;Close&quot;&gt;
                      &lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;
                      &lt;/button&gt;
                  &lt;/div&gt;
              {% endfor %}
           {% endif %}
      {% endwith %}
        &lt;div class=&quot;main-w3layouts wrapper&quot;&gt;
              &lt;div class=&quot;main-agileinfo&quot;&gt;
                  &lt;div class=&quot;agileits-top&quot;&gt;
                      &lt;form action=&quot;&quot; method=&quot;POST&quot;&gt;
                          &lt;input  type=&quot;text&quot; name=&quot;Username&quot; placeholder=&quot;Username&quot; value=&quot;{{request.form.get.Username}}&quot;&gt;
                          &lt;input  type=&quot;Email&quot; name=&quot;Email&quot; placeholder=&quot;Email&quot; value=&quot;{{request.form.get.Email}}&quot;&gt;
                          &lt;input  type=&quot;Password&quot; name=&quot;Password&quot; placeholder=&quot;Password&quot; value=&quot;{{request.form.get.Password}}&quot;&gt;
                          &lt;input  type=&quot;Password&quot; name=&quot;RepeatPassword&quot; placeholder=&quot;ConfirmPassword&quot; value=&quot;{{request.form.get.RepeatPassword}}&quot;&gt;
                          &lt;input type=&quot;submit&quot; value=&quot;SIGNUP&quot;&gt;
                      &lt;/form&gt;
                      &lt;p&gt;Don't have an Account? &lt;a href=&quot;{{ url_for('login') }} &quot;&gt; Login Now!&lt;/a&gt;&lt;/p&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      {% endblock %}
      {% endblock %}
  </code></pre>
  <h3>Login Page</h3>
  <pre><code>{% extends &quot;ESP_Base.html&quot; %}
  {% block title %}Enterprise App Support Console{% endblock %}
  {% block head %}
    {{ super() }}
  {% endblock %}
  {% block body %}
  {% block content %}
    &lt;h1&gt;Enterprise Appsuppor Login&lt;/h1&gt;
  {% with errors = get_flashed_messages() %}
       {% if errors %}
         {% for error in errors %}
          &lt;div class=&quot;alert alert-warning alert-dismissible fade show&quot; role=&quot;alert&quot;&gt;
                  &lt;strong&gt;{{ error }}&lt;/strong&gt;
                  &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;alert&quot; aria-label=&quot;Close&quot;&gt;
                  &lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;
                  &lt;/button&gt;
              &lt;/div&gt;
          {% endfor %}
       {% endif %}
  {% endwith %}
    &lt;div class=&quot;main-agileinfo&quot;&gt;
        &lt;div class=&quot;agileits-top&quot;&gt;
                  &lt;form action=&quot;&quot; method=&quot;POST&quot;&gt;
                      &lt;input type=&quot;text&quot; name=&quot;Username&quot; placeholder=&quot;Username&quot; &gt;
                      &lt;input type=&quot;password&quot; name=&quot;Password&quot; placeholder=&quot;Password&quot;&gt;
                      &lt;p&gt;&lt;input type = &quot;submit&quot; value = &quot;Login&quot;/&gt;&lt;/p&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
    &lt;/div&gt;
  {% endblock %}
  {% endblock %}
  </code></pre>
  <p>Can you please advice what could be the issue.</p>
  <p>Thanks in advance</p>