cyberai-1 commited on
Commit
85535f1
·
1 Parent(s): 9992528

Enforce password

Browse files
Files changed (2) hide show
  1. app.py +16 -2
  2. templates/register.html +10 -1
app.py CHANGED
@@ -167,6 +167,20 @@ def allowed_file(filename):
167
  return "." in filename and filename.rsplit(".", 1)[1].lower() in ALLOWED_EXTENSIONS
168
 
169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  def extension_from_url(url, content_type):
171
  path = urlparse(url).path
172
  if "." in path:
@@ -269,8 +283,8 @@ def register():
269
  flash("All fields are required.", "danger")
270
  elif password != confirm_password:
271
  flash("Passwords do not match.", "danger")
272
- elif len(password) < 6:
273
- flash("Password must contain at least 6 characters.", "danger")
274
  else:
275
  try:
276
  with get_db() as conn:
 
167
  return "." in filename and filename.rsplit(".", 1)[1].lower() in ALLOWED_EXTENSIONS
168
 
169
 
170
+ def validate_password_strength(password):
171
+ checks = [
172
+ (len(password) >= 10, "at least 10 characters"),
173
+ (any(char.islower() for char in password), "one lowercase letter"),
174
+ (any(char.isupper() for char in password), "one uppercase letter"),
175
+ (any(char.isdigit() for char in password), "one number"),
176
+ (any(not char.isalnum() for char in password), "one special character"),
177
+ ]
178
+ missing = [message for valid, message in checks if not valid]
179
+ if missing:
180
+ return "Password must contain " + ", ".join(missing) + "."
181
+ return None
182
+
183
+
184
  def extension_from_url(url, content_type):
185
  path = urlparse(url).path
186
  if "." in path:
 
283
  flash("All fields are required.", "danger")
284
  elif password != confirm_password:
285
  flash("Passwords do not match.", "danger")
286
+ elif validate_password_strength(password):
287
+ flash(validate_password_strength(password), "danger")
288
  else:
289
  try:
290
  with get_db() as conn:
templates/register.html CHANGED
@@ -19,7 +19,16 @@
19
 
20
  <label class="cyber-field">
21
  <span>Password</span>
22
- <input type="password" name="password" required autocomplete="new-password" placeholder="Minimum 6 characters">
 
 
 
 
 
 
 
 
 
23
  </label>
24
 
25
  <label class="cyber-field">
 
19
 
20
  <label class="cyber-field">
21
  <span>Password</span>
22
+ <input
23
+ type="password"
24
+ name="password"
25
+ required
26
+ minlength="10"
27
+ pattern="(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{10,}"
28
+ autocomplete="new-password"
29
+ placeholder="10+ chars, Aa, 1, symbol"
30
+ title="Use at least 10 characters with uppercase, lowercase, number, and special character">
31
+ <small class="password-rules">Use 10+ characters with uppercase, lowercase, number, and special character.</small>
32
  </label>
33
 
34
  <label class="cyber-field">