Skip to content

Instantly share code, notes, and snippets.

View lorenzobn's full-sized avatar

LorenzoB. lorenzobn

View GitHub Profile
@lorenzobn
lorenzobn / auth.html
Created September 19, 2021 08:43
HTML page that displays the second-step in 2FA
{% extends 'layout.html' %}
{% block body %}
<div class="row" id="title">
<h1>How to enable 2FA</h1>
</div>
<div class="row">
{% if secret_key %}
<div class="six columns">
<form action="/login/auth" method="GET">
<div class="row">
@lorenzobn
lorenzobn / server.py
Created September 19, 2021 08:41
2FA implemented
from flask import Flask, render_template, redirect, request, url_for, flash, session
import os
import pyotp
app = Flask(__name__)
@app.route("/")
def index():
return render_template('index.html')
@lorenzobn
lorenzobn / otp_auth.py
Created September 19, 2021 08:29
Snippet of code containing the verification function for 2FA
@app.route("/login/auth", methods=['GET', 'POST'])
def OTP_auth():
if session['username'] == None:
return redirect(url_for('login'))
if request.method == 'POST':
#verify OTP
totp_instance = pyotp.TOTP(app.config["OTP_CODE"])
valid = totp_instance.verify(request.form.get("otp"))
if valid:
return render_template("success.html")
@lorenzobn
lorenzobn / login.py
Last active September 19, 2021 08:31
Snippet of code containing the login route for 2FA
@app.route("/login", methods=['GET', 'POST'])
def login():
form_user = request.form.get("username")
form_pass = request.form.get("password")
if request.method == 'POST':
if form_user == app.config["USER"] and form_pass == app.config["PASS"]:
session['username'] = form_user
return redirect(url_for("OTP_auth"))
else:
flash("Invalid credentials. Please try again.")
@lorenzobn
lorenzobn / style.css
Created September 19, 2021 07:58
Stylying for 1FA web application
body {
margin: 5%;
}
#title{
border-bottom: 1px solid #222;
}
#title h1{
margin-bottom: 5%;
@lorenzobn
lorenzobn / index.html
Created September 18, 2021 11:35
Index of Flask1FA web application
{% extends 'layout.html' %}
{% block body %}
<div class="row" id="title">
<h1>Login</h1>
</div>
<form action="/login" method="POST">
<div class="row" id="first-line">
<div class="six columns">
<label for="username">Username</label>
<input class="u-full-width" type="text" placeholder="Your username" id="username" name="username" required>
@lorenzobn
lorenzobn / layout.html
Created September 18, 2021 11:29
The basic layout of Flask1FA web application
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Basic Page Needs
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta charset="utf-8">
<title>Login page with 2FA</title>
<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
@lorenzobn
lorenzobn / server.py
Last active September 18, 2021 13:10
Basic Flask web application with login form
from flask import Flask, render_template, redirect, request, url_for, flash
import os
app = Flask(__name__)
@app.route("/")
def index():
return render_template('index.html')
@app.route("/login", methods=['GET', 'POST'])
@lorenzobn
lorenzobn / retrieve_data.py
Last active September 11, 2021 08:12
Snippet taken from main.py with a focus on LSB retrieving function
while (end == False):
while (bit_i >= 0):
px = matrix[start_pixel]
# colors: Red, Green and Blue
for c in range(conf[0], conf[1]):
if bit_i >= 0:
# We are getting the LSB of the pixel color, and then we shift it to the left accordingly
byte += (px[c]&1)<<bit_i
bit_i -= 1
else:
@lorenzobn
lorenzobn / hide_data.py
Last active September 11, 2021 08:12
Snippet taken from main.py with a focus on LSB hiding function
start_pixel = get_num_rand(used_pixels, num_of_pixels)
while byte_written != len(input_data):
bit_i = 0
while bit_i != 8:
px = matrix[start_pixel]
# colors: Red, Green and Blue
for c in range(conf[0], conf[1]):
if bit_i == 8:
break
# Because of Least Significant Bit, we want to modify the last bit of every color