I'm making a script to try and hack into an account whose login password is at least 8 characters long and includes at least 1 number, 1 special character and 1 capital letter. I will use brute force. Is there a compact, elegant and efficient way to iterate through every possible string that matches a given regular expression? Are there any C# classes that already do this or will I have to invent the wheel?

Desired:

```
CoolClass pswExpIter = CoolClass(pswExp);
for ( string thisExp = pswdExpIter.first(); thisExp != pswdExpIter.offend(); thisExp = pswdExpIter.next())
{
if (login("John Doe", thisExp)
{
// do something
break;
}
}
```

# Best How To :

Let's say the domain is as following

```
String domain[] = { a, b, .., z, A, B, .. Z, 0, 1, 2, .. 9 };
```

Let's say the password size is 8

```
ArrayList allCombinations = getAllPossibleStrings2(domain,8);
```

This is going to generate `SIZE(domain) * LENGTH`

number of combinations, which is in this example `(26+26+10)^8 = 62^8 = 218,340,105,584,896`

combinations

Then you can enumerate all possible string up\at to a specific size like this

```
// get all possible combinations up to a given size
static ArrayList getAllPossibleStrings1(ArrayList domain, int maxSize)
{
ArrayList list = new ArrayList();
int i = 1;
list.AddRange(domain);
while(++i <= maxSize)
for(String a in list)
for(String b in domain)
list.Add(String.Concat(a,b));
return list;
}
// get all possible combinations at a given size
static ArrayList getAllPossibleStrings2(ArrayList domain, int size)
{
ArrayList list = new ArrayList();
ArrayList temp = new ArrayList();
int i = 1;
list.AddRange(domain);
while(++i <= maxSize)
{
for(String a in list)
for(String b in domain)
temp.Add(String.Concat(a,b));
list.Clear();
list.AddRange(temp);
temp.Clear();
}
return list;
}
```