aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Web/Attributes
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-21 22:13:16 +0200
committertranstrike <transtrike@gmail.com>2021-01-21 22:13:16 +0200
commit13a2ceda912f961a232c87236f1b29aa29bb6160 (patch)
tree59f8d2bf63b03bacc76f98114d2aed78e420ddcd /src/DevHive.Web/Attributes
parenta47ea20ab91017da53437f750ed8e0f939f5cdba (diff)
parentbda98b96433d7a9952524fab4ec65f96998b55de (diff)
downloadDevHive-13a2ceda912f961a232c87236f1b29aa29bb6160.tar
DevHive-13a2ceda912f961a232c87236f1b29aa29bb6160.tar.gz
DevHive-13a2ceda912f961a232c87236f1b29aa29bb6160.zip
Merge branch 'refactor_user_updating' into dev
Diffstat (limited to 'src/DevHive.Web/Attributes')
-rw-r--r--src/DevHive.Web/Attributes/GoodPasswordModelValidation.cs24
-rw-r--r--src/DevHive.Web/Attributes/OnlyAlphanumericsModelValidation.cs20
-rw-r--r--src/DevHive.Web/Attributes/OnlyLettersModelValidation.cs20
3 files changed, 64 insertions, 0 deletions
diff --git a/src/DevHive.Web/Attributes/GoodPasswordModelValidation.cs b/src/DevHive.Web/Attributes/GoodPasswordModelValidation.cs
new file mode 100644
index 0000000..7d6a1ea
--- /dev/null
+++ b/src/DevHive.Web/Attributes/GoodPasswordModelValidation.cs
@@ -0,0 +1,24 @@
+using System;
+using System.ComponentModel.DataAnnotations;
+
+namespace DevHive.Web.Attributes
+{
+ 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;
+ }
+ }
+}
diff --git a/src/DevHive.Web/Attributes/OnlyAlphanumericsModelValidation.cs b/src/DevHive.Web/Attributes/OnlyAlphanumericsModelValidation.cs
new file mode 100644
index 0000000..26e0733
--- /dev/null
+++ b/src/DevHive.Web/Attributes/OnlyAlphanumericsModelValidation.cs
@@ -0,0 +1,20 @@
+using System;
+using System.ComponentModel.DataAnnotations;
+
+namespace DevHive.Web.Attributes
+{
+ public class OnlyAlphanumerics : ValidationAttribute
+ {
+ public override bool IsValid(object value)
+ {
+ var stringValue = (string)value;
+
+ foreach (char ch in stringValue)
+ {
+ if (!Char.IsLetterOrDigit(ch))
+ return false;
+ }
+ return true;
+ }
+ }
+}
diff --git a/src/DevHive.Web/Attributes/OnlyLettersModelValidation.cs b/src/DevHive.Web/Attributes/OnlyLettersModelValidation.cs
new file mode 100644
index 0000000..07afee9
--- /dev/null
+++ b/src/DevHive.Web/Attributes/OnlyLettersModelValidation.cs
@@ -0,0 +1,20 @@
+using System;
+using System.ComponentModel.DataAnnotations;
+
+namespace DevHive.Web.Attributes
+{
+ public class OnlyLetters : ValidationAttribute
+ {
+ public override bool IsValid(object value)
+ {
+ var stringValue = (string)value;
+
+ foreach (char ch in stringValue)
+ {
+ if (!Char.IsLetter(ch))
+ return false;
+ }
+ return true;
+ }
+ }
+}