I want to create a code using
netuser
function that will search by clicking on the button:
private void NextForm3_Click(object sender, EventArgs e)
if the user by selecting an
Item
from
listbox
.
private void ExistUserList_SelectedIndexChanged(object sender, EventArgs e)
is in logged in computer, in Windows services. If it has an account second of all, it must search if it has the correct password from textbox:
private void FirstPassword_TextChanged(object sender, EventArgs e)
to computer, in Windows services. When both things are correct, the user can go to the next dialogbox.
What I have tried:
Whenever I write a random password to the selected user in
listbox
, I have access to go to from
Form2.cs to
Form3.cs. This is my selected, shorter version of my code:
private void NextForm3_Click(object sender, EventArgs e)
{
string selectedUsername = Username.Text;
string enteredPassword = FirstPassword.Text;
bool userExists = CheckIfUserExists(selectedUsername);
if (userExists)
{
bool passwordIsCorrect = CheckIfPasswordIsCorrect
(selectedUsername, enteredPassword);
if (passwordIsCorrect)
{
AllForm2 = AllText2.Text;
Form3 next3 = new Form3();
next3.Show();
this.Close();
}
else
{
}
}
else
{
}
}
private bool CheckIfUserExists(string username)
{
Process process = new Process();
process.StartInfo.FileName = "net";
process.StartInfo.Arguments = "user " + username;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return output.Contains(username);
}
private bool CheckIfPasswordIsCorrect(string username, string password)
{
Process process = new Process();
process.StartInfo.FileName = "net";
process.StartInfo.Arguments = "user " + username + " " + password;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return !output.Contains("The user name could not be found");
}