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:
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: