//Sign up button Adjustments
private void button1_Click(object sender, EventArgs e)
{
//Second Password label and textbox for sign up
label3.Visible = true;
PassBox2.Visible = true;
//Error message for username and password blank
if (CheckBlank(UserBox.Text, PassBox1.Text) == false)
{
MessageBox.Show("Username and Password must not be blank", "Error",MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//Error message for username and password length
else if (CheckLength(UserBox.Text, PassBox1.Text) == false)
{
MessageBox.Show("Username and Password must be at least 6 characters long", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//Error message for password confirmation
else if (CheckMatch(PassBox1.Text, PassBox2.Text) == false)
{
MessageBox.Show("Passwords must match", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//attend new values from text boxes to variables
else
{
username = UserBox.Text;
password = PassBox1.Text;
password2 = PassBox2.Text;
}
//Adressing UserInfo.csv file
string currentDirectory = Directory.GetCurrentDirectory();
//Error message for username already existing
if (CheckUsername(username) == true)
{
MessageBox.Show("Username already exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//Store the new user's username and hashed password in the UserInfo.csv file
else
{
StoreUserInfo(username, HashPassword(password));
MessageBox.Show("User created successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
大家好,这是我的代码,我想第二个密码文本框显示,当我点击注册按钮,然后稍后检查什么是预期的,但当我点击注册程序直接存储用户名和密码我该怎么办,我不能超过这个问题
1条答案
按热度按时间ubby3x7f1#
正如我在评论中提到的,你的代码使文本框可见,之后所有的注册过程继续进行。你需要将这两个动作分开。你的代码必须处理两种不同的情况。我在下面给出一个基本的例子。
除此之外,你可以看到保存操作时你的代码没有抛出错误,这是因为if块,你需要检查并重新组织你的if块(控件).