...

View Full Version : Asp.net C# problems using the Login Control



casto
03-21-2011, 04:33 AM
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...

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:

jency
05-06-2011, 05:51 AM
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 = "";
}
}

Rumesh Chanchal
09-12-2011, 11:13 AM
check out the following links....
http://www.mindstick.com/Articles/1bd75404-424e-4c84-ab55-28742117d6ad/?Login%20Control%20in%20ASP.Net

rock052
10-02-2011, 11:52 PM
hi i heared that visual basic is not used any more shouldn't i learn it or what?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum