aboutsummaryrefslogtreecommitdiff
path: root/src/Web/DevHive.Web.Models/Attributes/GoodPasswordAttribute.cs
blob: c452499d190b4c9245b2ac94bc754385f60e0dc6 (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
using System.ComponentModel.DataAnnotations;

namespace DevHive.Web.Models.Attributes
{
	public class GoodPasswordAttribute : 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;
		}
	}
}