How to verify that the password contains X uppercase letters and Y numbers?

前端 未结 4 2148
温柔的废话
温柔的废话 2021-02-09 01:31

How do I verify in C# that the password contains at least X uppercase letters and at least Y numbers, and the entire string is longer than Z?

Thanks.

4条回答
  •  伪装坚强ぢ
    2021-02-09 01:57

    This should do it:

    public bool CheckPasswordStrength(string password, int x, int y, int z)
    {
       return password.Length >= z &&
              password.Count(c => c.IsUpper(c)) >= x &&
              password.Count(c => c.IsDigit(c)) >= y;
    }
    

提交回复
热议问题