Go Back   CodingForums.com > :: Server side development > ASP.NET

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-21-2011, 04:33 AM   PM User | #1
casto
New to the CF scene

 
Join Date: Mar 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
casto is an unknown quantity at this point
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:
casto is offline   Reply With Quote
Old 05-06-2011, 05:51 AM   PM User | #2
jency
New to the CF scene

 
Join Date: May 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
jency is an unknown quantity at this point
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 = "";
}
}
jency is offline   Reply With Quote
Old 09-12-2011, 11:13 AM   PM User | #3
Rumesh Chanchal
New to the CF scene

 
Join Date: Sep 2011
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
Rumesh Chanchal is an unknown quantity at this point
Re: Asp.net login control

check out the following links....
http://www.mindstick.com/Articles/1b...20in%20ASP.Net
Rumesh Chanchal is offline   Reply With Quote
Old 10-02-2011, 11:52 PM   PM User | #4
rock052
Banned

 
Join Date: Aug 2011
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
rock052 is an unknown quantity at this point
hi i heared that visual basic is not used any more shouldn't i learn it or what?
rock052 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:12 AM.


Advertisement
Log in to turn off these ads.