Updated the password validation and created a username validation function.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user