Skip to content

Commit 4cf8efb

Browse files
committed
Added limit on user and password login length
1 parent 7f86d7c commit 4cf8efb

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

manager/src/app.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def login():
4747
username = request.form['username']
4848
password = request.form['password']
4949

50+
if username and password:
51+
if len(username) > 64 or len(password) > 64:
52+
return render_template('login.html')
53+
5054
auth_res = authenticate_basic(username, password)
5155
if auth_res and auth_res.get_success():
5256
# Reset failed login attempts for this client IP
@@ -64,18 +68,21 @@ def login():
6468
# Increment failed login attempts for this client IP
6569
failed_login_attempts[client_ip] += 1
6670

71+
flash("Invalid credentials", "error")
72+
6773
# increase the timeout based on the number of failed attempts
6874
if failed_login_attempts[client_ip] >= 10:
6975
Logger.log_info(f"Locking out client {client_ip} for 30 minutes due to too many failed login attempts.")
7076
timeouts[client_ip] = datetime.now() + timedelta(minutes=30)
77+
return render_template('lockout.html')
7178
elif failed_login_attempts[client_ip] >= 5:
7279
Logger.log_info(f"Locking out client {client_ip} for 10 minutes due to too many failed login attempts.")
7380
timeouts[client_ip] = datetime.now() + timedelta(minutes=10)
81+
return render_template('lockout.html')
7482
elif failed_login_attempts[client_ip] >= 3:
7583
Logger.log_info(f"Locking out client {client_ip} for 5 minutes due to too many failed login attempts.")
7684
timeouts[client_ip] = datetime.now() + timedelta(minutes=5)
77-
78-
flash("Invalid credentials", "error")
85+
return render_template('lockout.html')
7986

8087
return render_template('login.html')
8188

manager/src/templates/login.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
<h1>Login</h1>
1313
<form action="{{ url_for('login') }}" method="post">
1414
<label for="username">Username:</label>
15-
<input type="text" id="username" name="username" required>
15+
<input type="text" id="username" name="username" maxlength="64" required>
1616

1717
<label for="password">Password:</label>
18-
<input type="password" id="password" name="password" required>
18+
<input type="password" id="password" name="password" maxlength="64" required>
1919

2020
<button type="submit">Login</button>
2121
</form>

manager/src/templates/operators.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ <h1>Operators</h1>
5050
<h2 id="modal-title">Add Operator</h2>
5151
<form id="operator-form">
5252
<label for="username">Username:</label>
53-
<input type="text" id="username" name="username" required>
53+
<input type="text" id="username" name="username" maxlength="64" required>
5454

5555
<label for="password">Password:</label>
56-
<input type="password" id="password" name="password" required>
56+
<input type="password" id="password" name="password" maxlength="64" required>
5757
</form>
5858
<div class="modal-buttons">
5959
<button type="button" id="close-modal-btn" class="cancel-button">Cancel</button>

0 commit comments

Comments
 (0)