Click here to Skip to main content
15,896,730 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,
i created log in page with name and password fields.when i press enter it should display on a label.
but it is working correctly for the value which is stored recently to the database table only.the values which already stored in the table is not captured by this code.

i have a code like this.

C++
string name, password, query;
        name = txtloginname.Text;
        password = txtloginpwd.Text;
        query = "select username,password,trole from userInfo";//userInfo is my table name
        SqlDataReader dr;
        SqlCommand command = new SqlCommand(query, scon);
        dr = command.ExecuteReader();
        while (dr.Read())
        {
            if (name.Equals(dr["username"].ToString()))
            {
                if (password.Equals(dr["password"].ToString()))
                {
                    string role = dr["trole"].ToString();
                    if (role.Equals("STUDENT"))
                    {
                        lblget1.Text = "welcome to" + role;
                    }
                    else
                    {
                        lblget1.Text = "welcome to" + role;
                    }
                }
                else
                {
                    lblget1.Text = "password do not match";
                }
            }
            else
            {
                lblget1.Text = "not a valid user";

}
plz help me.
thank you.
Posted

1 solution

This is the worst login code I have ever seen. I'd fire you if you worked for me. NEVER pull the right data out of the database, always have the DB check if the user is valid. NEVER put DB code in the presentation layer, write a data layer.

select count (*) from userInfo where username = @username AND password = @password

OR select trole if you need to return it, and check if it's null.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900