Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C# I have made an application and in order to use the application, upon loadi

ID: 3718308 • Letter: I

Question

In C# I have made an application and in order to use the application, upon loading is a passwordForm, that take's the password and checks it with the hard-coded string constant as shown below, login class as defined below also. In the passwordForm I have a button to reset the password, essentially the same class as passworfForm but named, resetForm. Is it possible to change the password (as defined below) within this new class resetForm or do I need to store everything into an array? Any help would be greatly appreciated.

public partial class passwordForm : Form
{
//masterpassword hardcoded into program
const string masterPass = "CapsLock";
loginClass credentials = new loginClass(masterPass);

}

Login Class as defined:

namespace AdminInterface

{
class loginClass
{

//decalre properties
  
public string Userpassword { get; set; }

  

//intialize
public loginClass(string pass)
{
this.Userpassword = pass;
}
//validate string
private bool StringValidator(string input)
{
string pattern = "[^a-zA-Z]";
if (Regex.IsMatch(input, pattern))
{
return true;
}
else
{
return false;
}
}
//validate integer
private bool IntegerValidator(string input)
{
string pattern = "[^0-9]";
if (Regex.IsMatch(input, pattern))
{
return true;
}
else
{
return false;
}
}
//clear user inputs
private void ClearTexts(string user, string pass)
{
user = String.Empty;
pass = String.Empty;
}
//method to check if eligible to be logged in
public bool IsLoggedIn(string pass)
{
//check user name empty
//check password is empty
  
if (string.IsNullOrEmpty(pass))
{
MessageBox.Show("Enter the passowrd!");
return false;
}
//check password is correct
else if (Userpassword != pass)
{
MessageBox.Show("Password is incorrect, Please re-enter");
return false;
}
else
{
return true;
}}}}

Explanation / Answer

Well, your question is little unclear. But still, let me try to answer as much as possible.

If you are going to have only one user or I mean only one password ro reset, which means only one person can login to your application, then the resetForm you are talking about, will work .

But, if you want there could be multiple users whom you would like to let login to your application, then I guess there will be multiple passwords (until you want all of them to login with the same password), then you need an array, right?

Now, the last and most important part - It is recommended to use some kind of database in these kind of applications and then store the details (user/password) in there and retrieve and update using a query language e.g. sql.

So, in summary, only 1 password (1 user or multiple users) to reset - your resetForm will work.

Multiple passwords (Multiple users) - you will need an array