Added code to support password settings. Fixed a bug where the [FromBody] attribute resulted in null object properties, as well as included more null checks.

This commit is contained in:
2021-03-09 22:14:29 -06:00
parent 70bb9dd9e2
commit 7008621799
53 changed files with 157 additions and 4377 deletions
+3 -3
View File
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
@@ -9,12 +7,13 @@ namespace SecureCore.Services
{
public static class UserDataService
{
//
public static int UserNameMaxLength { get; } = 64;
public static int UserNameMinLength { get; } = 3;
public static int EmailMaxLength { get; } = 512;
public static (bool IsValid, string Message) IsUsernameValid(string userName)
{
if (string.IsNullOrEmpty(userName) || userName.Length < UserNameMinLength) return (false, $"Username is too short, the user name must be at least {UserNameMinLength} characters long.");
if (userName.Length > UserNameMaxLength) return (false, $"Username too long, must not exceed {UserNameMaxLength} characters.");
var invalidChars = new List<char>();
@@ -62,6 +61,7 @@ namespace SecureCore.Services
public static (bool IsValid, string Message) IsEmailValid(string email)
{
if (string.IsNullOrEmpty(email)) return (false, "The provided email is not in the correct format.");
if (email.Length > EmailMaxLength) return (false, $"Email exceeds the maximum length of {EmailMaxLength} characters.");
//Code taken from user "Cogwheel" on StackOverflow: https://stackoverflow.com/questions/1365407/c-sharp-code-to-validate-email-address