Updated the password validation and created a username validation function.

This commit is contained in:
2021-01-12 20:12:38 -06:00
parent c2297ed368
commit 4e25410d30
4 changed files with 47 additions and 5 deletions
+19
View File
@@ -10,8 +10,27 @@ namespace SecureCore.Services
{
public static class UserDataService
{
//
public static int UserNameMaxLength { get; } = 64;
private static string ConnectionString = @"Server=DESKTOP-OEDDVKC\SQLEXPRESS;Database=main;Integrated Security=true;";
public static (bool IsValid, string Message) UserNameIsValid(string userName)
{
if (userName.Length > UserNameMaxLength) return (false, $"Username to long, must not exceed {UserNameMaxLength} characters.");
var invalidChars = new List<char>();
foreach(var c in userName)
{
if (char.IsPunctuation(c) || char.IsSymbol(c) || char.IsControl(c) || char.IsSeparator(c) || char.IsWhiteSpace(c)) invalidChars.Add(c);//return (false, $"The character '{c}' is not allowed.");
}
if (invalidChars.Count > 0) return (false, $"The characters '{string.Join(",", invalidChars)}' are not allowed in a user name.");
return (true, string.Empty);
}
public static (string PasswordHash, string SaltHash) GetUserPasswordHash(string userName)
{
var userId = GetUserId(userName);