diff --git a/config.ini.example b/config.ini.example index 8525cbd..5f4b067 100644 --- a/config.ini.example +++ b/config.ini.example @@ -1,5 +1,13 @@ -[HectaMail] +[Signup] # Secret Key, please change to something custom secretkey: secret_key_here # The characters you allow in your CAPTCHA captchachars: ABCDEFGHIJKLMNOPQRSTUVWXYZ +# The port the server should run on +port: 8050 + +[Login] +# The port the server should run on +port: 8040 +# The location of the maddy database +dblocation: /var/lib/maddy/credentials.db diff --git a/login/login.py b/login/login.py new file mode 100644 index 0000000..5e1296c --- /dev/null +++ b/login/login.py @@ -0,0 +1,57 @@ +from flask import Flask, render_template, request +import bcrypt +import sqlite3 +import configparser +from waitress import serve + +# Load from config.ini + +config = configparser.ConfigParser() +config.read("config.ini") +database = config.get("Login", "database") +runport = config.get("Login", "port") + +# Status report + +print("HectaMail Login Service is starting up...") +print("Your database is located at:", database) + +app = Flask(__name__) + +def fetch_hash_from_database(key): + conn = sqlite3.connect(database) + cursor = conn.cursor() + cursor.execute("SELECT value FROM passwords WHERE key = ?", (key,)) + result = cursor.fetchone() + conn.close() + + if result: + return result[0][7:] # Remove the first 7 characters + else: + return None + +def verify_bcrypt(passphrase, hashed_password): + return bcrypt.checkpw(passphrase.encode('utf-8'), hashed_password.encode('utf-8')) + +@app.route('/') +def index(): + return render_template('index.html') + +@app.route('/login', methods=['POST']) +def login(): + key_to_fetch = request.form['email'] + password_to_check = request.form['password'] + + go_script_hash = fetch_hash_from_database(key_to_fetch) + + if go_script_hash: + is_password_valid = verify_bcrypt(password_to_check, go_script_hash) + if is_password_valid: + return "Logged in successfully" + else: + return "Incorrect email or password" + else: + return "Email not found in the database" + +if __name__ == '__main__': + serve(app, host='0.0.0.0', port=runport) diff --git a/login/templates/index.html b/login/templates/index.html new file mode 100644 index 0000000..f0bb4d6 --- /dev/null +++ b/login/templates/index.html @@ -0,0 +1,32 @@ + +
+ +