gpt4 book ai didi

需要 C# 密码帮助

转载 作者:太空宇宙 更新时间:2023-11-03 18:27:34 26 4
gpt4 key购买 nike

我是 C# 新手。我正在尝试在 textbox1 中输入密码以登录我的表单。此登录按钮启用某些控件。这行得通。这是问题开始的地方。我也做了一个更改密码部分,我在文本框 2 中输入旧密码,在文本框 3 中输入新密码,并在文本框 4 中确认密码。我想要的是从 textbox3 或 textbox4 更新密码,然后将其设置为密码。因此,在文本框 3 或文本框 4 中输入的任何内容现在都是密码。当我在 textbox1 中输入这个新的更改密码时,它会登录。我已经尝试了所有我能想到的方法,但没有解决方案。这是我正在使用的代码。

private void button14_Click(object sender, EventArgs e) // Main Screen Password Login Button
{
String passWord;
passWord = "login";

if (textBox1.Text == passWord)
{
passWord = textBox3.Text;
// textBox1.Clear();
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = true;
button4.Enabled = true;
button5.Enabled = true;
button6.Enabled = true;
button7.Enabled = true;
button8.Enabled = true;
button9.Enabled = true;
button10.Enabled = true;
button11.Enabled = true;
button12.Enabled = false;
button16.Enabled = true;
button16.Visible = true;
button20.Enabled = true;
numericUpDown1.Enabled = true;
numericUpDown2.Enabled = true;

button14.Click += ResetTimer;
}

else
{
MessageBox.Show("Password is Incorrect");
textBox1.Clear();
}
}
private void button19_Click(object sender, EventArgs e) // Admin Confirm Old Password Button
{
// String passWord;
// passWord = textBox2.Text;

if (textBox1.Text == textBox2.Text)
{
//MessageBox.Show("Password is Correct");
textBox3.Enabled = true;
textBox4.Enabled = true;
}
else
{
MessageBox.Show("Password is Incorrect");
}
private void button17_Click(object sender, EventArgs e) // Admin Update New password Button
{
String passWord;
//passWord = textBox3.Text;

// passWord = textBox3.Text;
// passWord = textBox4.Text;

if(textBox3.Text == textBox4.Text)
{
passWord = textBox3.Text;
MessageBox.Show("Password Changed");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox3.Enabled = false;
textBox4.Enabled = false;

}
else
{
MessageBox.Show("Password Does Not Match");
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox3.Enabled = false;
textBox4.Enabled = false;
}
button17.Click += ResetTimer;
}

因此,当我单击 button17 时,我希望将密码更改为在 textbox3 或 textbox4 中输入的内容。这个新密码将用于登录 textbox1。我希望我正确地描述了我的问题。任何帮助都感激不尽。谢谢。詹妮弗。

最佳答案

button17_Click() 中,您有一个名为 passWord 的局部变量。当您分配新值时,您将其分配给该局部变量。在 button19_Click() 中,您有另一个不同的同名局部变量。请阅读MSDN on Variable and Method Scope马上!

您需要的是一个全局变量,它存储有效密码,并删除所有具有该名称的局部变量。只需将全局用于登录和更改过程。

关于需要 C# 密码帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30779424/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com