aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Web/Attributes/GoodPasswordModelValidation.cs
blob: 7d6a1eab18714cefd0d670d186a399dcd74b6771 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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;
		}
	}
}