mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
refactor: implement password validation in dto; remove redundant validation code in auth controller
This commit is contained in:
@@ -36,11 +36,7 @@ namespace SharpbinV3.Server.Controllers
|
||||
var existingEmailUser = await _userService.GetByEmail(request.Email);
|
||||
if (existingEmailUser != null)
|
||||
return Conflict(new { message = "Email already in use." });
|
||||
if (!IsValidEmail(request.Email))
|
||||
return BadRequest(new { message = "Invalid email." });
|
||||
}
|
||||
if (!IsValidPassword(request.Password))
|
||||
return BadRequest(new { message = "Password should have at least 8 characters, including uppercase, lowercase, and digits." });
|
||||
if (!string.IsNullOrEmpty(request.DisplayName) && request.DisplayName.Length > 26)
|
||||
return BadRequest(new { message = "Display name should not exceed 26 characters." });
|
||||
|
||||
@@ -112,31 +108,5 @@ namespace SharpbinV3.Server.Controllers
|
||||
registration_enabled = authSettings.Registration_Enabled
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private static bool IsValidPassword(string password)
|
||||
{
|
||||
if (password.Length < 6)
|
||||
return false;
|
||||
if (!password.Any(char.IsUpper))
|
||||
return false;
|
||||
if (!password.Any(char.IsLower))
|
||||
return false;
|
||||
if (!password.Any(char.IsDigit))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
private static bool IsValidEmail(string email)
|
||||
{
|
||||
try
|
||||
{
|
||||
var addr = new System.Net.Mail.MailAddress(email);
|
||||
return addr.Address == email;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user