-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCluster Connect.py
38 lines (28 loc) · 1.02 KB
/
Cluster Connect.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
from flask import Flask, render_template, request, jsonify
import pickle
from scipy.spatial import distance
from password_strength import PasswordStats
app = Flask(__name__)
@app.route('/')
def index():
return render_template('MLpg.html')
@app.route("/", methods=["POST"])
def clus():
with open('model1.pkl', 'rb') as f:
kmeans = pickle.load(f)
distances = []
password = request.form['password']
pass_len = len(password)
pass_complex = PasswordStats(password).strength()
for i in range(kmeans.n_clusters):
p1 = (kmeans.cluster_centers_[i])
p2 = (pass_len, pass_complex)
d = distance.euclidean(p1, p2)
distances.append(d)
# print(distances)
clus_names = ['Highly Breachable', 'Partially Unbreachable', 'Partially Breachable', 'Highly UnBreachable']
low = distances.index(min(distances))
result = clus_names[low]
return jsonify({"pw": result})
if __name__ == '__main__':
app.run(debug=True)