-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
50 lines (41 loc) · 1.73 KB
/
app.py
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
44
45
46
47
48
49
50
from flask import Flask, render_template, request
import hashlib
from zxcvbn import zxcvbn
from passlib import pwd
app = Flask(__name__)
# Load common passwords into a set
def load_common_passwords(file_path):
return_set = set()
try:
with open(file_path, 'r') as file:
for line in file:
line = line.strip()
hashed_password = hashlib.sha256(line.encode()).hexdigest()
# add to return set
return_set.add(hashed_password)
except FileNotFoundError:
return set()
return return_set
password_set1 = load_common_passwords('10k-most-common.txt')
password_set2 = load_common_passwords('10-million-password-list-top-1000000.txt')
password_set3 = load_common_passwords('500-worst-passwords.txt')
password_set = password_set1.union(password_set2).union(password_set3)
def gen_better_password(curPassword):
newPass = pwd.genphrase(entropy=30, wordset="eff_long", sep="");
return newPass;
@app.route('/')
def index():
return render_template('index.html')
@app.route('/check_password', methods=['POST'])
def check_password():
password = request.form['password']
result = zxcvbn(password)
score = result['score']
feedback = result['feedback']['suggestions']
hashed = hash_password(password)
is_common_password = hash_password(password) in password_set
return render_template('result.html', hashed_password=hashed, is_common=is_common_password, password=password, score=score, feedback=feedback, better=gen_better_password(password), better_score=zxcvbn(gen_better_password(password))['score'])
def hash_password(password):
return hashlib.sha256(password.encode()).hexdigest()
if __name__ == '__main__':
app.run(debug=True)