Add complexity requirements for passwords

This commit is contained in:
Parker M. 2024-09-20 18:26:40 -05:00
parent 1acb17b3af
commit cf6e4be30f
No known key found for this signature in database
GPG Key ID: 95CD2E0C7E329F2A
2 changed files with 12 additions and 1 deletions

View File

@ -76,6 +76,14 @@ def signup():
username = request.form["username"] username = request.form["username"]
password = request.form["password"] password = request.form["password"]
# Verify the password meets requirements
if len(password) < 8:
return {"status": "Password must be at least 8 characters"}
if not any(char.isdigit() for char in password):
return {"status": "Password must contain at least one digit"}
if not any(char.isupper() for char in password):
return {"status": "Password must contain at least one uppercase letter"}
# Get database session # Get database session
db = SessionLocal() db = SessionLocal()

View File

@ -7,7 +7,7 @@
</head> </head>
<body> <body>
<div> <div>
<p id="error">User already exists. Please try again</p> <p id="error"></p>
<form action="/signup" method="POST"> <form action="/signup" method="POST">
<input type="text" name="username" placeholder="Username" required> <input type="text" name="username" placeholder="Username" required>
<input type="password" name="password" placeholder="Password" required> <input type="password" name="password" placeholder="Password" required>
@ -15,6 +15,7 @@
</form> </form>
<hr> <hr>
<p>Already have an account? <a href="/login">Log in now</a></p> <p>Already have an account? <a href="/login">Log in now</a></p>
<p>Passwords must be at least 8 characters long and contain a number, special character, and uppercase character.</p>
</div> </div>
</body> </body>
</html> </html>
@ -33,6 +34,7 @@
left: 50%; left: 50%;
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
text-align: center; text-align: center;
max-width: 330px;
} }
input { input {
@ -104,6 +106,7 @@
if (data.status != "success") { if (data.status != "success") {
document.getElementById('error').style.display = 'block'; document.getElementById('error').style.display = 'block';
document.getElementById('error').innerText = data.status;
} else { } else {
window.location.href = '/dashboard'; window.location.href = '/dashboard';
} }