This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from PIL import Image | |
import sys, argparse, random | |
EOF_MARKER = '$eof!' | |
confs = {'RGB':[0,3], 'RGBA':[1,4]} | |
def calculate_min_size(number_of_bits): | |
"""Calculates the minimum image size needed to contain number_of_bits""" | |
min_pxls = number_of_bits//3 # 1 pixel = 3 bits stored |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<!-- Basic Page Needs | |
–––––––––––––––––––––––––––––––––––––––––––––––––– --> | |
<meta charset="utf-8"> | |
<title>Login page with 2FA</title> | |
<!-- CSS | |
–––––––––––––––––––––––––––––––––––––––––––––––––– --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 5%; | |
} | |
#title{ | |
border-bottom: 1px solid #222; | |
} | |
#title h1{ | |
margin-bottom: 5%; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
OlderNewer