如果密码不正确,请发送电子邮件用户密码

时间:2014-03-21 01:04:23

标签: c#

 private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            var sr = new System.IO.StreamReader("C:\\" + textBox1.Text + "\\login.text");
            username = sr.ReadLine();
            password = sr.ReadLine();
            email = sr.ReadLine();
            sr.Close();
            if (username == textBox1.Text && password == passwordtextbox.Text)
                MessageBox.Show("Success!");



        }
        catch(System.IO.DirectoryNotFoundException )
        {
            MessageBox.Show("Error, please check your email for password, else try again.");
            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();

如果密码输入不正确,我的目标是向用户发送密码。但是,该用户名必须与电子邮件匹配!那么,我该怎么做?

1 个答案:

答案 0 :(得分:0)

您只想发表else if声明

if (username == textBox1.Text && password == passwordtextbox.Text)
{
    MessageBox.Show("Success!");
}
else if(textBox1.Text == email)
{
    //Send email
}

但我的猜测是,您正试图在catch声明中处理此问题,而username声明无效。你的逻辑是有缺陷的。如果找不到所提供的用户名,则会引发您正在捕获的异常。这意味着您无法阅读任何内容,eamilpasswordcatchcatch语句中没有值。在这种情况下,您的if-else逻辑应该提示用户尝试使用其他用户名。然后上面的{{1}}逻辑将起作用。

相关问题