You must Sign In to post a response.
  • Category: ASP.NET

    Check user name and password before login

    Hello Developers,
    Am created a login page.I want to check the username and password is correct or not.if is correct it is goes to another page.else it display a error message like incorrect user name or password. But now the username is working 100% fine but the password is not well.i mean if i giving any password it willl goes to home page.if any error in my code please correct and help me.
    This is my code for login.aspx.cs.


    protected void btnsubmit_Click(object sender, EventArgs e)
    {
    OleDbConnection con = Connection.DBconnection();
    DataSet ds = new DataSet();
    string userlogin = "select * from tbl_Registration where Emailid='" + txtname.Text.Trim() + "' or Mobile='" + txtname.Text.Trim() + "' and Pwd='" + txtpassword.Text.Trim() + "'";
    OleDbDataAdapter oda = new OleDbDataAdapter(userlogin, con);
    oda.Fill(ds);
    if (ds.Tables[0].Rows.Count > 0)
    {
    Session["uid"] = txtname.Text.Trim();
    Response.Redirect("User/UserHome.aspx");
    }
    else
    {
    lblalert.Text = "Incorrect user name or Password";
    }
    }

    With thanks
    Paul.S
  • #762114
    Hi Paul Raj,

    I seen your previous posts too, you are asking to check the code is correct or not..?

    Why can't you check by your self the same..?

    Please check your Select Query, and execute the same in SQL Manager and see whether its return any records to that or not.

    If you have any troubleshoot issue to resolve the problem then you can raise it, we can workout and provide the solution for the same.

    Before asking a question you should recheck whether this is a question or not..?

    As per your post I strongly believe that this is not a question, because we don't know your database records, as per your code you checked database records if there is a data irrespective of logins obviously it will redirect to Home page. If not it's showing error message as you mentioned in your code.

    First off all put a break point and see the execution plan how it's running then decide what is the cause of the issue this is the way everyone doing.

    As per your posts I understood that you are a fresher, as a fresher you should be concentrate more in execution plan then only you can understand the code logic's.

    Please take my words in +ve way, try and try and try until you succeed, then only you can enjoy the sweetness of success, if you stolen others work you can't enjoy that sweetness.

    Hope you understood...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #762115
    Hello Paul Raj,

    You should check the query and it's values what it is getting while executing it.

    Refer the below links :

    http://www.aspsnippets.com/Articles/Simple-User-Login-Form-example-in-ASPNet.aspx

    http://www.c-sharpcorner.com/uploadfile/abhikumarvatsa/simple-login-project-in-Asp-Net/

    http://www.dotnetfunda.com/articles/show/808/how-to-write-a-simple-login-page-in-aspnet

    http://www.aspdotnet-suresh.com/2011/12/how-to-create-simple-login-form-using.html

    https://www.daniweb.com/software-development/csharp/threads/24148/simple-asp-net-login-page-using-c

    Hope this will work for you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #762116

    Hi

    Change the column in the database table, make it as username. Then in the username textbox user can enter mail id or phone number. what ever he enter, store it as username in database.

    Now take input Username and password from form that's it.

    code will be as follows

    protected void btnsubmit_Click(object sender,
    EventArgs e)
    {
    OleDbConnection con = Connection.DBconnection
    ();
    DataSet ds = new DataSet();
    string userlogin = "select * from tbl_Registration
    where Username='" + txtname.Text.Trim() + "' and Pwd='" +txtpassword.Text.Trim() + "'";
    OleDbDataAdapter oda = new OleDbDataAdapter
    (userlogin, con);
    oda.Fill(ds);
    if (ds.Tables[0].Rows.Count > 0)
    {
    Session["uid"] = txtname.Text.Trim();
    Response.Redirect("User/UserHome.aspx");
    }
    else
    {
    lblalert.Text = "Incorrect user name or Password";
    }
    }

    This will not redirect to Home, if you give any one i.e., username or password value as wrong.

    Regards

    Sridhar Thota.


    Sridhar Thota.
    Editor: DNS Forum.

  • #762121
    yeah thank you mr.Naveen ,No No i don,t take mistake,Your right.Thank you.

  • #762126
    Hi Paul Raj,

    Thanks for your understanding...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments