From 7e7498d368514a3e61e5df868fe6ff14dc568601 Mon Sep 17 00:00:00 2001 From: jvyden Date: Tue, 22 Feb 2022 16:36:46 -0500 Subject: [PATCH] Enforce 3-16 character limit on usernames --- ProjectLighthouse/Database.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ProjectLighthouse/Database.cs b/ProjectLighthouse/Database.cs index 385982bf..c8d0ef87 100644 --- a/ProjectLighthouse/Database.cs +++ b/ProjectLighthouse/Database.cs @@ -46,7 +46,10 @@ public class Database : DbContext public async Task CreateUser(string username, string password) { - if (!password.StartsWith("$")) throw new ArgumentException(nameof(password) + " is not a BCrypt hash"); + if (!password.StartsWith('$')) throw new ArgumentException(nameof(password) + " is not a BCrypt hash"); + + // 16 is PSN max, 3 is PSN minimum + if (username.Length > 16 || username.Length < 3) throw new ArgumentException(nameof(username) + " is either too long or too short"); User user; if ((user = await this.Users.Where(u => u.Username == username).FirstOrDefaultAsync()) != null) return user;