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