public static bool IsValid(string password, EUserPasswordRestriction restriction)
        {
            var isValid = false;

            if (!string.IsNullOrEmpty(password))
            {
                if (restriction == EUserPasswordRestriction.None)
                {
                    isValid = true;
                }
                else if (restriction == EUserPasswordRestriction.LetterAndDigit)
                {
                    var isLetter = false;
                    var isDigit  = false;
                    foreach (var c in password)
                    {
                        if (char.IsLetter(c))
                        {
                            isLetter = true;
                        }
                        else if (char.IsDigit(c))
                        {
                            isDigit = true;
                        }
                    }
                    if (isLetter && isDigit)
                    {
                        isValid = true;
                    }
                }
                else if (restriction == EUserPasswordRestriction.LetterAndDigitAndSymbol)
                {
                    var isLetter = false;
                    var isDigit  = false;
                    var isSymbol = false;
                    foreach (var c in password)
                    {
                        if (char.IsLetter(c))
                        {
                            isLetter = true;
                        }
                        else if (char.IsDigit(c))
                        {
                            isDigit = true;
                        }
                        else if (char.IsSymbol(c))
                        {
                            isSymbol = true;
                        }
                    }
                    if (isLetter && isDigit && isSymbol)
                    {
                        isValid = true;
                    }
                }
            }
            return(isValid);
        }
示例#2
0
        public static ListItem GetListItem(EUserPasswordRestriction type, bool selected)
        {
            var item = new ListItem(GetText(type), GetValue(type));

            if (selected)
            {
                item.Selected = true;
            }
            return(item);
        }
示例#3
0
 public static bool Equals(EUserPasswordRestriction type, string typeStr)
 {
     if (string.IsNullOrEmpty(typeStr))
     {
         return(false);
     }
     if (string.Equals(GetValue(type).ToLower(), typeStr.ToLower()))
     {
         return(true);
     }
     return(false);
 }
示例#4
0
 public static string GetText(EUserPasswordRestriction type)
 {
     if (type == EUserPasswordRestriction.None)
     {
         return("不限制");
     }
     if (type == EUserPasswordRestriction.LetterAndDigit)
     {
         return("字母和数字组合");
     }
     if (type == EUserPasswordRestriction.LetterAndDigitAndSymbol)
     {
         return("字母、数字以及符号组合");
     }
     throw new Exception();
 }
示例#5
0
 public static string GetValue(EUserPasswordRestriction type)
 {
     if (type == EUserPasswordRestriction.None)
     {
         return("None");
     }
     if (type == EUserPasswordRestriction.LetterAndDigit)
     {
         return("LetterAndDigit");
     }
     if (type == EUserPasswordRestriction.LetterAndDigitAndSymbol)
     {
         return("LetterAndDigitAndSymbol");
     }
     throw new Exception();
 }
示例#6
0
 public static bool Equals(string typeStr, EUserPasswordRestriction type)
 {
     return(Equals(type, typeStr));
 }