I'm writing code to determine whether a password contains enough punctuation characters.
How do I count the number of occurrences of any characters from a set?
Something along these lines:
private const string nonAlphaNumericCharSet = "#*!?£$+-^<>[]~()&";
...
public static bool PasswordMeetsStrengthRequirements(string password)
{
return password.Length >= MINIMUM_PASSWORD_LENGTH && password.NumberOfOccurences(nonAlphaNumericCharSet.ToCharArray()) >= MINIMUM_NONALPHANUMERIC_CHARS;
}
Bonus points for an elegant linq solution.