(app.py) file: # Store this code in 'app.py' file   from flask import Flask, render_template, request, redirect, url_for, session from flask_mysqldb import MySQL import MySQLdb.cursors import re     app = Flask(__name__) if __name__ == "__main__":     app.run(debug=True)     app.secret_key = 'your secret key'   app.config['MYSQL_HOST'] = 'localhost' app.config['MYSQL_USER'] = 'root' app.config['MYSQL_PASSWORD'] = '' app.config['MYSQL_DB'] = '' mysql = MySQL(app)   @app.route('/') @app.route('/login', methods =['GET', 'POST']) def login():     msg = ''     if request.method == 'POST' and 'username' in request.form and 'password' in request.form:         username = request.form['username']         password = request.form['password']         cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)         cursor.execute('SELECT * FROM accounts WHERE username = % s AND password = % s', (username, password, ))         account = cursor.fetchone()         if account:                         msg = 'Logged in successfully !'             return render_template('index.html', msg = msg)         else:             msg = 'Incorrect username / password !'     return render_template('login.html', msg = msg)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Task question:

 

Step 1. You have been asked to add code in given template file “app.py” to enable login using employee table in test database. First

Create Data Base: test

Create table: employee

Table fields:

 

Id

Int

10(primary key) auto increment

username

Varchar

25

Password

Varchar

25

EmpMail

Varchar

25

 With 2 records

1

Manager

Manager123

manager@gmail.com

2

Teller

Teller123

teller@gmail.com

 

 

Login should have username and password field. You are asked to add SQL code to get successful login.

Step 2. you should also add error message if credentials are wrong-Validation step

Step 3:  Add code to login .html template file to create Login form using text and password fields.

Step 4. Add button to get sign-in action

Step 5: you should save the file in relevant locations to avoid path and output issues.

Step 6. You should have proper database connectivity to succeed in this lab worksheet. Successful connection to database also will be counted for marking.

 

Show your outputs through screenshots.

 

 

 

(app.py) file:

# Store this code in 'app.py' file
 
from flask import Flask, render_template, request, redirect, url_for, session
from flask_mysqldb import MySQL
import MySQLdb.cursors
import re
 
 
app = Flask(__name__)
if __name__ == "__main__":
    app.run(debug=True)
 
 
app.secret_key = 'your secret key'
 
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = ''
app.config['MYSQL_DB'] = ''
mysql = MySQL(app)
 
@app.route('/')
@app.route('/login', methods =['GET', 'POST'])
def login():
    msg = ''
    if request.method == 'POST' and 'username' in request.form and 'password' in request.form:
        username = request.form['username']
        password = request.form['password']
        cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
        cursor.execute('SELECT * FROM accounts WHERE username = % s AND password = % s', (username, password, ))
        account = cursor.fetchone()
        if account:
           
            msg = 'Logged in successfully !'
            return render_template('index.html', msg = msg)
        else:
            msg = 'Incorrect username / password !'
    return render_template('login.html', msg = msg)

Step 1. You have been asked to add code in given template file "app.py" to enable login using
employee table in test database. First
Create Data Base: test
Create table: employee
Table fields:
Id
username
Password
EmpMail
With 2 records
1
2
Int
Varchar
Varchar
Varchar
Manager
Teller
10(primary key) auto increment
25
25
25
Manager 123
Teller 123
manager@gmail.com
teller@gmail.com
Login should have username and password field. You are asked to add SQL code to get
successful login.
Step 2. you should also add error message if credentials are wrong-Validation step
Step 3: Add code to login .html template file to create Login form using text and password
fields.
Step 4. Add button to get sign-in action
Step 5: you should save the file in relevant locations to avoid path and output issues.
Transcribed Image Text:Step 1. You have been asked to add code in given template file "app.py" to enable login using employee table in test database. First Create Data Base: test Create table: employee Table fields: Id username Password EmpMail With 2 records 1 2 Int Varchar Varchar Varchar Manager Teller 10(primary key) auto increment 25 25 25 Manager 123 Teller 123 manager@gmail.com teller@gmail.com Login should have username and password field. You are asked to add SQL code to get successful login. Step 2. you should also add error message if credentials are wrong-Validation step Step 3: Add code to login .html template file to create Login form using text and password fields. Step 4. Add button to get sign-in action Step 5: you should save the file in relevant locations to avoid path and output issues.
Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Linux
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education