using System;
namespace Business.KftcPasswordRule
{
///
///
public class DboValidationRule : PasswordRule
{
///
///
///
public PasswordValidationResult Validate(ValidationModel model)
{
string[] dobArr = null;
string dateOfBirth = "";
if (model.IdType.ToLower() == "passport" || model.IdType.Trim().Equals("10997"))
{
dobArr = model.Dob.Split('/');
string mm = dobArr[0], dd = dobArr[1];
if (dobArr[0].Length == 1)
{
mm = "0" + mm;
}
if (dobArr[1].Length == 1)
{
dd = "0" + dd;
}
dateOfBirth = dobArr[2].Substring(0, 4) + mm + dd;
}
else
{
dateOfBirth = model.IdNumber.Substring(0, 6);
string yy = "19" + dateOfBirth.Substring(0, 2);
int nowYear = DateTime.Now.Year;
if ((nowYear - Convert.ToInt16(yy)) > 80)
{
yy = "20" + dateOfBirth.Substring(0, 2);
}
dateOfBirth = yy + dateOfBirth.Substring(2, 4);
}
string dateOfBirth1 = dateOfBirth.Substring(0, 4);
string dateOfBirth2 = dateOfBirth.Substring(2, 6);
string dateOfBirth3 = dateOfBirth.Substring(4, 4);
if (model.Password.Contains(dateOfBirth1))
{
return new PasswordValidationResult { IsValid = false, Message = "Password can not be same as DOB!" };
}
if (model.Password.Contains(dateOfBirth2))
{
return new PasswordValidationResult { IsValid = false, Message = "Password can not be same as DOB!" };
}
if (model.Password.Contains(dateOfBirth3))
{
return new PasswordValidationResult { IsValid = false, Message = "Password can not be same as DOB!" };
}
return new PasswordValidationResult { IsValid = true, Message = "valid password" };
}
}
}