aboutsummaryrefslogtreecommitdiff
path: root/src/Web/DevHive.Web.Models/Attributes/GoodPasswordModelValidation.cs
blob: 5ecb41ad0888aa5bd0dd560b5aee902cd7e48987 (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.Models.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;
		}
	}
}