Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, render_template, request, redirect, url_for, make_response, jsonify
- import random, sqlite3, datetime, time
- app = Flask(__name__)
- banned_ip = []
- file = open('banned_ips.txt', 'r')
- print("Banned IPs:")
- for line in file:
- print(line)
- banned_ip.append(line)
- @app.route('/', methods=['GET', 'POST'])
- def login():
- ### VARIABLES ###
- conn = sqlite3.connect('leakedsarp.db')
- c = conn.cursor()
- #################
- if(request.method == 'POST'):
- info = ''
- user_data = []
- username = request.form['username'].lower()
- password = request.form['password']
- ip = str(request.remote_addr)
- #c.execute("INSERT INTO logs VALUES({},{},{})".format(ip, username, password))
- conn.commit()
- if(len(username) < 1 or len(password) < 1):
- return render_template('index.html', info='Username or password must be greater than one character.')
- else: #If input is provided, the below query searches the database and compares the username to others.
- select = c.execute("SELECT * FROM accounts WHERE lower(username)=? LIMIT 1", [username])
- for row in select.fetchall(): #Fetches the rows and imports them into an array.
- for data in row:
- user_data.append(data) #Makes sure each entry is a different list item.
- if(len(user_data) == 0): # Returns 0 if there is no account.
- info = 'Username "{}" not found.'.format(username)
- return render_template('index.html', info=info)
- else: # Otherwise an account is found and compares with the data.
- if(user_data[1].lower() == username and user_data[2] == password):
- logged_in = True
- return render_template('index.html', info="Welcome", logged_in=logged_in)
- else:
- return render_template('index.html', info="Invalid Password")
- else:
- if(request.remote_addr in banned_ip):
- return "IP address {} is banned.".format(request.remote_addr)
- return render_template('index.html')
- @app.route("/ip", methods=["GET"])
- def get_my_ip():
- return request.remote_addr
- if (__name__ == '__main__'):
- app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement