vendredi 11 décembre 2020

Simple Password Tester C#

I'm tinkering with a very basic password tester. I'm trying to compare the input string with a given string of acceptable characters.

public static bool hasRequiredChar(string input)
{
    input = "input";
    string requiredChar = "abcde";

    foreach (var item in requiredChar)
    {
        if (input.Contains(item)) return true;
    }

    return false;
}

If I only use System, I get the error message: "Argument 1: cannot convert from 'char' to 'string'". This refers to the string.Contains() method. Any ideas?

I know there are 1000 ways to write this differently but I don't want to use Regex, Linq or anything other than System.

Aucun commentaire:

Enregistrer un commentaire