diff --git a/AceJobAgency/Controllers/UserController.cs b/AceJobAgency/Controllers/UserController.cs index d993882..e70c19b 100644 --- a/AceJobAgency/Controllers/UserController.cs +++ b/AceJobAgency/Controllers/UserController.cs @@ -1,8 +1,10 @@ using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; +using System.Text.RegularExpressions; using AceJobAgency.Data; using AceJobAgency.Entities; +using AceJobAgency.Utilities; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.IdentityModel.Tokens; @@ -25,8 +27,13 @@ namespace AceJobAgency.Controllers [HttpPost("register")] public async Task Register(User user) { - bool emailExists = _context.Users.Any(u => u.Email == user.Email); - bool nricExists = _context.Users.Any(u => + if (!AccountManagement.IsPasswordComplex(user.Password)) + { + return BadRequest("Password must be at least 12 characters long and include uppercase, lowercase, number, and special character."); + } + + var emailExists = _context.Users.Any(u => u.Email == user.Email); + var nricExists = _context.Users.Any(u => u.NationalRegistrationIdentityCardNumber == user.NationalRegistrationIdentityCardNumber); if (emailExists || nricExists) { diff --git a/AceJobAgency/Utilities/AcountManagement.cs b/AceJobAgency/Utilities/AcountManagement.cs new file mode 100644 index 0000000..d9cf465 --- /dev/null +++ b/AceJobAgency/Utilities/AcountManagement.cs @@ -0,0 +1,20 @@ +using System.Text.RegularExpressions; + +namespace AceJobAgency.Utilities; + +public class AccountManagement +{ + public static bool IsPasswordComplex(string password) + { + if (string.IsNullOrEmpty(password) || password.Length < 12) + return false; + + // Require at least one uppercase, one lowercase, one digit, and one special character + bool hasUpperCase = Regex.IsMatch(password, @"[A-Z]"); + bool hasLowerCase = Regex.IsMatch(password, @"[a-z]"); + bool hasDigit = Regex.IsMatch(password, @"\d"); + bool hasSpecialChar = Regex.IsMatch(password, @"[^a-zA-Z0-9]"); + + return hasUpperCase && hasLowerCase && hasDigit && hasSpecialChar; + } +} \ No newline at end of file