diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-12-16 12:28:28 +0200 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-12-16 12:28:28 +0200 |
| commit | 5ae2e175dc6f32bc662b0c84b17855216714f874 (patch) | |
| tree | 2895e5c91e4c85492e1a01233875b6bee793d6a0 /src/DevHive.Web/Models | |
| parent | c50beb167dabe08d6407b54630bfe2b47eab23e6 (diff) | |
| download | DevHive-5ae2e175dc6f32bc662b0c84b17855216714f874.tar DevHive-5ae2e175dc6f32bc662b0c84b17855216714f874.tar.gz DevHive-5ae2e175dc6f32bc662b0c84b17855216714f874.zip | |
Added password strength validation
Diffstat (limited to 'src/DevHive.Web/Models')
| -rw-r--r-- | src/DevHive.Web/Models/Identity/User/RegisterWebModel.cs | 1 | ||||
| -rw-r--r-- | src/DevHive.Web/Models/Identity/Validation/GoodPasswordModelValidation.cs | 24 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/DevHive.Web/Models/Identity/User/RegisterWebModel.cs b/src/DevHive.Web/Models/Identity/User/RegisterWebModel.cs index c82263e..60e860a 100644 --- a/src/DevHive.Web/Models/Identity/User/RegisterWebModel.cs +++ b/src/DevHive.Web/Models/Identity/User/RegisterWebModel.cs @@ -28,6 +28,7 @@ namespace DevHive.Web.Models.Identity.User public string LastName { get; set; } [Required] + [GoodPassword] public string Password { get; set; } } } diff --git a/src/DevHive.Web/Models/Identity/Validation/GoodPasswordModelValidation.cs b/src/DevHive.Web/Models/Identity/Validation/GoodPasswordModelValidation.cs new file mode 100644 index 0000000..f69121a --- /dev/null +++ b/src/DevHive.Web/Models/Identity/Validation/GoodPasswordModelValidation.cs @@ -0,0 +1,24 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace DevHive.Web.Models.Identity.Validation +{ + public class GoodPassword : ValidationAttribute + { + public override bool IsValid(object value) + { + var stringValue = (string)value; + + for (int i = 0; i < stringValue.Length; i++) + { + if (Char.IsDigit(stringValue[i])) + { + base.ErrorMessage = "Password must be atleast 5 characters long!"; + return stringValue.Length >= 5; + } + } + base.ErrorMessage = "Password must contain atleast 1 digit!"; + return false; + } + } +} |
