我有这个代码有问题。它是登录软件。我想限制每个员工的一些辅助功能。但它不起作用。实际上,我在menu
加载时制作了enabled=false
所有选项。我应该如何使用c#编写登录代码?
这是窗体后面的代码。形式有2 textboxes
,它们中的一个是用于username
,另一个是用于password
和具有一个Enter
按钮。
private void Enter_Click(object sender, EventArgs e)
{
if (txtPassword.Text == "10")
{
FormMenu a = new FormMenu();
this.Hide();
a.EmployeManagement.Enabled = true;
a.Sabtenam.Enabled = true;
a.Shora.Enabled = true;
a.HozorGhiab.Enabled = true;
a.Ketabkhane.Enabled = true;
new FormMenu().Show();
a.Refresh();
}
else
if (txtPassword.Text == "20")
{
FormMenu a = new FormMenu();
this.Hide();
a.Sabtenam.Enabled = true;
a.HozorGhiab.Enabled = true;
new FormMenu().Show();
}
else
if (txtPassword.Text == "30")
{
FormMenu a = new FormMenu();
this.Hide();
a.Shora.Enabled = true;
new FormMenu().Show();
}
else
if (txtPassword.Text == "40")
{
FormMenu a = new FormMenu();
this.Hide();
a.HozorGhiab.Enabled = true;
new FormMenu().Show();
}
else
if (txtPassword.Text == "50")
{
FormMenu a = new FormMenu();
this.Hide();
a.Shora.Enabled = true;
new FormMenu().Show();
}
else
if (txtPassword.Text == "60")
{
FormMenu a = new FormMenu();
this.Hide();
a.Ketabkhane.Enabled = true;
new FormMenu().Show();
}
else
MessageBox.Show("Invalid username or password");
}
不要硬编码密码。 [哈希](https://crackstation.net/hashing-security.htm)。然后使用[RBAC](https://en.wikipedia.org/wiki/Role-based_access_control)模式来定义菜单可访问性。 – Martheen