Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
43 lines (39 loc) · 1.42 KB
/
Copy pathapp.py
File metadata and controls
43 lines (39 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from flask import Flask, render_template_string, request
from password_utils import sha256_hash, salted_sha256, bcrypt_hash, argon2_hash
from password_checker import score_password
app = Flask(__name__)
HTML_PAGE = """
<!doctype html>
<title>Test Mot de Passe</title>
<h2>Test de mot de passe</h2>
<form method=post>
Mot de passe: <input type=password name=password>
<input type=submit value=Tester>
</form>
{% if result %}
<hr>
<p><b>Score:</b> {{result.score}} /8 — Niveau: {{result.strength}}</p>
{% if result.reasons %}<p><b>Suggestions:</b> {{result.reasons|join(', ')}}</p>{% endif %}
<p><b>SHA-256:</b> {{hashes.sha256}}</p>
<p><b>Salted SHA-256:</b> {{hashes.salted}} (salt hex: {{hashes.salt}})</p>
<p><b>bcrypt:</b> {{hashes.bcrypt}}</p>
<p><b>argon2:</b> {{hashes.argon2}}</p>
{% endif %}
"""
@app.route('/', methods=['GET','POST'])
def index():
result = None
hashes = None
if request.method == 'POST':
pw = request.form.get('password', '')
if pw:
result = score_password(pw)
sha = sha256_hash(pw)
salted, salt = salted_sha256(pw)
bcrypt_h = bcrypt_hash(pw)
argon2_h = argon2_hash(pw)
hashes = {"sha256": sha, "salted": salted, "salt": salt,
"bcrypt": bcrypt_h, "argon2": argon2_h}
return render_template_string(HTML_PAGE, result=result, hashes=hashes)
if __name__ == '__main__':
app.run(debug=True)