This repository has been archived by the owner on Nov 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
97 lines (74 loc) · 2.55 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import os
from flask import Flask, render_template, request
app = Flask(__name__, template_folder='templates')
# Function to check common passwords from file
def checkfile(x):
# Password file forked from https://github.com/danielmiessler/SecLists/blob/master/Passwords/Common-Credentials/10k-most-common.txt
with open("10k-most-common.txt", 'r') as file:
for line in file:
if x in line:
return True
return False
def pswdcheck(a):
special_characters = "\"\'!@ #$%^&*()-+?_=,<>/"
strength = 0
allnumber = True
# Check right away to reduce time
if checkfile(a):
return "Password found in common password database. Please change ASAP!"
# Convert string into list
pswd = [x for x in a]
# 6 < Password Length < 12
if len(pswd) < 6 or len(pswd) > 12:
return "The password must be at least 6 and no more than 12 characters long"
# Check if all lower or upper or contains only numbers
if not(a.islower() or a.isupper()):
if not(a.isnumeric()):
strength += 1
# Check if password is all numeral
if not(a.isnumeric()):
allnumber = False
elif a.isnumeric:
allnumber = True
if not allnumber:
# Checking if there are any numerals
for item in pswd:
if item.isnumeric():
strength += 1
break
# Check if there are any special characters
for item in pswd:
if item in special_characters:
strength += 1
break
# Assign values
if strength == 0:
strength = "Weak"
elif strength == 1:
strength = "Medium"
elif strength == 2:
strength = "Strong"
elif strength == 3:
strength = "OVERPOWERED"
return "Password accepted.\nPassword Strength: " + str(strength)
# / directory
@app.route('/')
def form():
return render_template('form.html')
# /data directory
@app.route('/data', methods=['POST', 'GET'])
def data():
# someone might access it directly with a GET request
if request.method == 'GET':
return f"Trying to test my website eh? It's foolproof"
# receiving POST request from form.html
if request.method == 'POST':
form_data = request.form
for key, value in form_data.items():
a = value
result = pswdcheck(a)
return render_template('data.html', result=result)
if __name__ == "__main__":
# Tries to retrieve the port from Heroku
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)