-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
221 lines (174 loc) · 6.67 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
from flask import Flask, render_template, request
from flask_socketio import SocketIO, emit
import random
import string
import time
import re
import math
app = Flask(__name__, static_url_path='/gui', static_folder='gui')
socketio = SocketIO(app)
with open('common-words.txt', 'r') as file:
common_words = [line.strip() for line in file]
def time_forecasted(password):
characters = 94
guesses_per_second = 550000 / characters
permutations = characters ** len(password)
seconds_required = permutations / guesses_per_second
return seconds_required
def contains_common_word(password):
with open('common-words.txt', 'r') as file:
common_words = [line.strip() for line in file]
for word in common_words:
if word.lower() in password.lower():
return True
return False
def contains_date_pattern(password):
date_patterns = [
r'\d{4}-\d{2}-\d{2}', # YYYY-MM-DD
r'\d{2}-\d{2}-\d{4}', # MM-DD-YYYY
r'\d{2}/\d{2}/\d{4}', # MM/DD/YYYY
r'\d{4}/\d{2}/\d{2}', # YYYY/MM/DD
r'\d{2}-\d{2}-\d{2}', # MM-DD-YY
r'\d{2}/\d{2}/\d{2}', # MM/DD/YY
]
for pattern in date_patterns:
if re.search(pattern, password):
return True
return False
def calculate_unique_characters(password):
char_frequency = {}
for char in password:
char_frequency[char] = char_frequency.get(char, 0) + 1
unique_characters = 0
password_length = len(password)
for char, frequency in char_frequency.items():
probability = frequency / password_length
unique_characters -= probability * math.log2(probability)
return unique_characters
def contains_leet_speak(password):
leet_dict = {
'a': ['4', '@'],
'b': ['8'],
'c': ['(', '<', '{', '['],
'e': ['3'],
'g': ['9', '6'],
'h': ['#'],
'i': ['1', '!', '|'],
'l': ['1', '|', '7'],
'o': ['0'],
's': ['5', '$'],
't': ['+', '7'],
'z': ['2']
}
modified_password = password.lower()
for char, substitutions in leet_dict.items():
for substitution in substitutions:
modified_password = modified_password.replace(substitution, char)
return modified_password != password.lower() and contains_common_word(modified_password)
def generate_random_characters(length, characters):
return ''.join(random.choice(characters) for _ in range(length))
app = Flask(__name__, static_url_path='/gui', static_folder='gui')
@app.route('/')
def index():
return render_template('index.html')
@app.route('/generate')
def generate_home():
return render_template('generate.html')
@app.route('/test')
def test_home():
return render_template('test.html')
@app.route('/crack')
def crack_home():
return render_template('crack.html')
@app.route('/generate/pressed', methods=['POST'])
def generate():
length = int(request.form['length'])
include_uppercase = 'uppercase' in request.form
include_lowercase = 'lowercase' in request.form
include_digits = 'digits' in request.form
include_special = 'special' in request.form
characters = ''
if include_uppercase:
characters += string.ascii_uppercase
if include_lowercase:
characters += string.ascii_lowercase
if include_digits:
characters += string.digits
if include_special:
characters += '!@#$%^&*()_+[]{}|;:,.<>?'
if not characters:
return render_template('generate.html', error="Choose at least one option to generate.")
password = generate_password(length, characters)
return render_template('generate.html', password=password)
def generate_password(length, characters):
password = ''.join(random.choice(characters) for _ in range(length))
return password
@app.route('/test/pressed', methods=['POST'])
def test():
password = request.form['password']
criteria = [
(len(password) >= 12, "At least 12 characters", 1),
(any(c.isupper() for c in password), "Contains an uppercase letter", 1),
(any(c.islower() for c in password), "Contains a lowercase letter", 1),
(any(c.isdigit() for c in password), "Contains a digit", 1),
(any(c in string.punctuation for c in password), "Contains a special character", 1),
(not contains_common_word(password), "Contains a common word", 1),
(not contains_date_pattern(password), "Avoids date patterns", 1),
(calculate_unique_characters(password) > 2.5, "Mix of unique characters", 1),
(not contains_leet_speak(password), "Avoids leet speak", 1)
]
analysis = []
total_points = 0
for condition, description, points in criteria:
if condition:
total_points += points
analysis.append(f'✅ {description} (+{points} point)')
else:
analysis.append(f'❌ {description}')
if total_points >= 7:
strength = "Strong"
elif total_points >= 4:
strength = "Medium"
else:
strength = "Weak"
return render_template('test.html', strength=strength, password=password, analysis=analysis, total=total_points)
@app.route('/crack/pressed', methods=['POST'])
def crack():
password = request.form['password']
start_time = time.time()
attempts = 0
forecasted_time = time_forecasted(password)
attempt = None
time_taken = None
while True:
attempt = generate_random_characters(len(password), string.ascii_letters + string.digits + string.punctuation)
attempts += 1
if attempt == password:
end_time = time.time()
time_taken = end_time - start_time
break
# Send updates to the client using WebSocket
socketio.emit('crack_update', {
'attempt': attempt,
'attempts': attempts,
'time_forecasted': int(float(forecasted_time)),
'time_taken': "{:.2f}".format(time_taken),
}, namespace='/crack')
return render_template('crack.html', password=password, attempt=attempt, attempts_formatted='{:,}'.format(attempts), time_forecasted=int(float(forecasted_time)), time_taken="{:.2f}".format(time_taken), show_loading_message=False)
@socketio.on('connect', namespace='/crack')
def handle_crack_connect():
print('Client connected to crack namespace')
@socketio.on('disconnect', namespace='/crack')
def handle_crack_disconnect():
print('Client disconnected from crack namespace')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/faq')
def faq():
return render_template('faq.html')
@app.route('/passfraze')
def passfraze():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)