I'm doing a brute-force project as a school assignment and I have to get a user input (password) with a maximum length of 12 characters and "hack" it. Every input with a length of 4 characters or less goes flawlessly. However, anything longer than that, and the app freezes and for some weird reason, stops the loop and also prevents any further interaction with the UI.
I thought maybe adding a label to the Form and changing its Text every time the hacking loop is run would solve the issue. But then I realized that, since everything is running through the main Form, this is not a solution.
Here's the function that hacks the user input:
private void startbtn_Click(object sender, EventArgs e)
{
okay = true;
charstring = "";
vpasswort = " " + passwordtb.Text.ToString();
passwort = vpasswort.Substring(vpasswort.Length - 12);
var time = new System.Diagnostics.Stopwatch();
time.Start();
do
{
int ende = letters.Length - 1;
for(int hmi = 0; hmi <= ende; hmi++)
{
//MessageBox.Show(charstring);
for (int zmi = 0; zmi <= ende; zmi++)
{
//MessageBox.Show(charstring);
for (int mi = 0; mi <= ende; mi++)
{
//MessageBox.Show(charstring);
for (int hm = 0; hm <= ende; hm++)
{
//MessageBox.Show(charstring);
for (int zm = 0; zm <= ende; zm++)
{
//MessageBox.Show(charstring);
for (int m = 0; m <= ende; m++)
{
//MessageBox.Show(charstring);
for (int ht = 0; ht <= ende; ht++)
{
//MessageBox.Show(charstring);
for (int zt = 0; zt <= ende; zt++)
{
//MessageBox.Show(charstring);
for (int t = 0; t <= ende; t++)
{
//MessageBox.Show(charstring);
for (int h = 0; h <= ende; h++)
{
//MessageBox.Show(charstring);
for (int z = 0; z <= ende; z++)
{
//MessageBox.Show(charstring);
for (int E = 0; E <= ende; E++)
{
charstring = letters[hmi] + letters[zmi] + letters[mi] + letters[hm] + letters[zm] +
letters[m] + letters[ht] + letters[zt] + letters[t] + letters[h] + letters[z] +
letters[E];
Console.WriteLine(charstring);
if(charstring == passwort)
{
okay = false;
time.Stop();
goto pizza;
}
//MessageBox.Show(charstring);
}//E
}//z
}//h
}//t
}//zt
}//ht
}//m
}//zm
}//hm
}//mi
}//zmi
}//hmi
} while (okay == true);
pizza:
MessageBox.Show("Your password was hacked!");
result.Text = charstring;
stopwatch.Text = time.ElapsedMilliseconds.ToString() + " ms";
}
//tried to change something in the form but didn't work
private void timer1_Tick(object sender, EventArgs e)
{
result.Text = charstring;
}
And so here's the main question. Is there a way for me to, say, pause the loop for one or two milliseconds to prevent the Application from freezing and/or crashing? I'm pretty sure there is a way and that it's really simple and that I just have this problem because I'm new to C# and Programming in general.
EDIT: I think I have to figure out a way to make the whole hacking process go on in the background. But, again, no idea how xD
Thank you in advance for any help!