aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DevHive.Web/Models/Identity/User/RegisterWebModel.cs1
-rw-r--r--src/DevHive.Web/Models/Identity/Validation/GoodPasswordModelValidation.cs24
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;
+ }
+ }
+}