Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Everyone,


I have designed a login form and i want it to function like this,

User will enter his/her username and password to texboxes.
The correct details must come from the database.
If the user enters the wrong details and must restrict the user.

Can you please comment when doing the codes because i dont want to do craming stuff.


Thanks for your help.
Posted
Comments
OriginalGriff 7-May-13 9:31am    
"Can you please comment when doing the codes because i dont want to do craming stuff."

Sorry? I'm not sure I understand what you are asking us to do.
Member 10010198 7-May-13 9:36am    
E.g
private void btnexit_Click(object sender, EventArgs e)
{
Application.Exit(); // a method that exit the application
}
OriginalGriff 7-May-13 9:37am    
Do you mean that you want us to write the code for you, but be sure to comment it well so you don't have to think about it?
Orcun Iyigun 7-May-13 9:49am    
So demanding ain't it? How much will you charge him? :)
Member 10010198 7-May-13 9:52am    
send an invoice.........joking

See How to create Login page[^]

Cheers,
Edo
 
Share this answer
 
you can generate a connectionstring programarically if its usre name and password of sql server database instance.

or if user information is stored inside a table you can set up a query.
some thing like this:
SQL
if    exists
(
   Select   UserName,Password   From Users    Where UserName = @UserName 
   And Password  = @Password
) return 1
else
  return 0
 
Share this answer
 
Comments
Member 10010198 7-May-13 9:54am    
Must i create a class for this
Try this I've already implemented this
C#
public bool login(string id, string entered_password)
    {
 public SqlConnection con = new SqlConnection("Data Source=[Server Name];Initial Catalog=[Database Name];User ID=[User];Password=[Password]");
        con.Open();
        string query = "SELECT [userpass] FROM userlogin WHERE [userid]=@id";
        SqlCommand cmdChk = new SqlCommand(query, con);
        cmdChk.Parameters.Add("@id", SqlDbType.VarChar).Value = id;
        SqlDataReader dr = cmdChk.ExecuteReader();
        int count = 0;
        string password = "";
        while (dr.Read())
        {
            count++;
            password= dr[0].ToString();
        }

        dr.Close();
        con.Close();
        if (count < 1)
        {
            return false;

        }
        else
        {
            if (password == entered_password)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
 
Share this answer
 
Comments
Member 10010198 7-May-13 9:55am    
Thanks.....will this code works even if theres no username and password stored as a default?

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