简体   繁体   English

使用Oledb Access的登录系统

[英]Login system using Oledb Access

I made a login page were the employee type in employee email address and then their pin. 我做了一个登录页面,输入的是员工的电子邮件地址,然后是他们的密码。 The idea is for the program to check the email and the pin form a Access database to successfully log them in. This is the code that I used. 这个想法是让程序检查电子邮件,并在Access数据库中形成图钉以成功登录。这是我使用的代码。

 private void Validate(object sender, RoutedEventArgs e)
    {
        OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\\Users\\Baladi\\documents\\visual studio 2012\\Projects\\CalUnderFoot\\CalUnderFoot\\UserPerm.mdb");           
        OleDbCommand cmd = null;
        OleDbDataReader dr = null;

        string cmdStr = String.Format("select * from UserPermT where EmpEmail='{0}' and EmpPIN='{1}'", EmpEmailtxt.Text, EmpPINtxt.PasswordChar);

        con.Open();
        cmd = new OleDbCommand(cmdStr, con);
        dr = cmd.ExecuteReader();

        cmd.Dispose();

        if (dr.Read() == true)
        {
            MessageBox.Show("success");
        }

        else
        {
            MessageBox.Show("fail");
        }

        dr.Dispose();
    }

When I enter the wrong email and pin I get a message saying "fail" which is what it supposed to do. 当我输入错误的电子邮件并输入密码时,我会收到一条消息,说“失败”,这是应该执行的操作。 BUT, when I enter the right email and pin I still get the "fail" message. 但是,当我输入正确的电子邮件并固定时,我仍然收到“失败”消息。 What am I missing?? 我想念什么? And yes I know... I am not supposed to store passwords in databases and I will encrypt them in due time. 是的,我知道...我不应该将密码存储在数据库中,我会在适当的时候对其进行加密。 Thank you in advance 先感谢您

Try something like this: 尝试这样的事情:

private void Validate(object sender, RoutedEventArgs e)
    {

    using (OleDbConnection connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\\Users\\Baladi\\documents\\visual studio 2012\\Projects\\CalUnderFoot\\CalUnderFoot\\UserPerm.mdb"))
    {
        OleDbCommand command = new OleDbCommand("select * from UserPermT where EmpEmail='"+EmpEmail.Text+"' and EmpPIN='"+EmpPIN.PasswordChar+"'", connection);
        connection.Open();
        OleDbDataReader dr= command.ExecuteReader();

        if (dr.Read())
        {
            MessageBox.Show("success");
        }

        else
        {
            MessageBox.Show("fail");
        }
        dr.Close();
    }
    }

(from http://msdn.microsoft.com/en-us/library/979byfca.aspx ) (来自http://msdn.microsoft.com/zh-cn/library/979byfca.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM