Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Asp.net C# problems using the Login Control

    I am using the asp.net Login controls and i am having trouble using the member.validateuser method.. I am using the database that comes with visual web developer and using the right credentials and sqlconnection but it keeps saying that the credentials are wrong any help would be appreciated...
    Code:
    login.aspx
    
    <asp:Login ID="Login1" runat="server" BackColor="#F7F7DE" BorderColor="#CCCC99" 
            BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="10pt" 
            onauthenticate="Login1_Authenticate" DestinationPageUrl="~/default.aspx">
            <TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="#FFFFFF" />
        </asp:Login>
    
    login.aspx.cs
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class login : System.Web.UI.Page
    {
        private SqlConnection hookup;
        private SqlCommand mycommand;
        string lookup = "";
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    
    
        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            try
            {
                hookup = new SqlConnection("Server=localhost\\SqlExpress;Database=VoteNow;" +
                "integrated Security=True");
                mycommand = new SqlCommand("Select ignacio WHERE username='@username' AND password='@password'",hookup);
                mycommand.Parameters.AddWithValue("@username",Login1.UserName);
                mycommand.Parameters.AddWithValue("@password", Login1.Password);
                hookup.Open();
                lookup = Convert.ToString(mycommand.ExecuteScalar());
                hookup.Close();
            }
            catch(Exception)
            {
            }
            if (Membership.ValidateUser(Login1.UserName, Login1.Password))
            {
                FormsAuthentication.RedirectFromLoginPage(Login1.UserName, true);
                Response.Redirect("default.aspx",true);
    
            }
            
    
    
        }
        
    }
    :eek:

  • #2
    New to the CF scene
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using System.Windows.Forms;
    public partial class first : System.Web.UI.Page
    {
    public static string objcon = ConfigurationManager.AppSettings["con"].ToString();
    SqlConnection con = new SqlConnection(objcon);
    SqlCommand cmd;
    SqlDataReader rd;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    string a = Convert.ToString(TextBox1.Text);
    string b = Convert.ToString(TextBox2.Text);
    if (a == "admin" && b == "admin")
    {
    Session["user"] = "admin";
    Response.Redirect("adminentrypge.aspx");
    }
    else
    {
    con.Open();
    cmd = new SqlCommand("select uname,pwd from staff where uname='" + a + "' and pwd='" + b + "'", con);
    rd = cmd.ExecuteReader();
    if (rd.HasRows)
    {
    while (rd.Read())
    {
    Session["staff"] = Convert.ToString(rd.GetValue(0));
    Response.Redirect("staffhme.aspx");
    }
    }
    else
    Label1.Text = "Check Your uid and pwd";
    con.Close();
    }
    }
    protected void Button5_Click(object sender, EventArgs e)
    {
    Label4.Visible = true;
    Label5.Visible = true;
    Label6.Visible=true;
    TextBox3.Visible = true;
    TextBox4.Visible = true;
    TextBox5.Visible=true;
    Button3.Visible = true;
    Button4.Visible = true;
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
    string a = Convert.ToString(TextBox3.Text);
    string b = Convert.ToString(TextBox4.Text);
    string c = Convert.ToString(TextBox5.Text);
    con.Open();
    cmd = new SqlCommand("update staff set pwd='" + b + "'where uname='" + c + "'", con);
    cmd.ExecuteNonQuery();
    Response.Write("<script>alert('Your password was changed')</script>");
    con.Close();
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
    Label4.Visible = false;
    Label5.Visible = false;
    Label6.Visible = false;
    TextBox3.Visible = false;
    TextBox4.Visible = false;
    TextBox5.Visible = false;
    Button3.Visible = false;
    Button4.Visible = false;

    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }




    protected void Button2_Click(object sender, EventArgs e)
    {
    TextBox1.Text = "";
    TextBox2.Text = "";
    }
    }

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Asp.net login control

    check out the following links....
    http://www.mindstick.com/Articles/1b...20in%20ASP.Net

  • #4
    Banned
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi i heared that visual basic is not used any more shouldn't i learn it or what?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •