hi, there, i came up with thisd login page. i came up with username , password and result textbox. i have included the C# behind code. i want to use roles and membership, but don't know how. i am not suppose to come up with any dropdownlist or textbox for that. i have also included the sql stored procedure codes. please help. its urgent. i have three roles including manager, delivery boy and customer.

<asp:TextBox ID="txtUsername" runat="server" style="z-index: 100; left: 319px; position: absolute; top: 17px" />
    <asp:TextBox ID="txtPassword" TextMode="Password" runat="server" style="z-index: 101; left: 320px; position: absolute; top: 54px"></asp:TextBox>
    <asp:TextBox TextMode="MultiLine" ID="txtShowResults" runat="server" style="z-index: 102; left: 182px; position: absolute; top: 169px" Height="129px" Width="363px"></asp:TextBox>
        &nbsp;
    <asp:Button ID="mybutton" runat="server" OnClientClick="return LenofPassword();" Text="Submit" style="z-index: 103; left: 295px; position: absolute; top: 95px" OnClick="mybutton_Click" Width="114px" />
        <asp:Label ID="Label1" runat="server" Style="z-index: 104; left: 210px; position: absolute;
            top: 19px" Text="Username" Width="88px"></asp:Label>
        <asp:Label ID="Label2" runat="server" Style="z-index: 105; left: 214px; position: absolute;
            top: 55px" Text="Password" Width="82px"></asp:Label>
        <asp:Label ID="Label3" runat="server" Style="z-index: 107; left: 324px; position: absolute;
            top: 135px" Text="Result" Width="39px"></asp:Label>
 
[B]Behind c# code[/B]
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
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;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void mybutton_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection("couriersystemconnectinstring");
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "insertmytable";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add(new SqlParameter("@Username", SqlDbType.VarChar));
        cmd.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar));
        SqlParameter result = new SqlParameter("@Result", SqlDbType.VarChar, 50);
        result.Direction = ParameterDirection.Output;
        SqlParameter returnValue = new SqlParameter("returnVal", SqlDbType.Int);
        returnValue.Direction = ParameterDirection.ReturnValue;
        cmd.Parameters.Add(returnValue);
        cmd.Parameters.Add(result);
        cmd.Parameters["@Username"].Value = txtUsername.Text;
        cmd.Parameters["@Password"].Value = txtPassword.Text;
        cmd.Connection = conn;
        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();
        txtShowResults.Text = result.Value.ToString() + " as number of users already existing with same user name and password is " + returnValue.Value.ToString() + Environment.NewLine;
    }
}

sql stored procedure

CREATE TABLE [utable] (
	[username] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[password] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	CONSTRAINT [PK_utable] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
) ON [PRIMARY]
GO


SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
CREATE PROCEDURE insertmytable
(
         @Username      VarChar(50),
	 @Password 	varchar(50),
         @Result        VarChar(50) output
)
AS 
DECLARE @num int
Select @num = count(*) from utable where username = @Username and password= @Password
if(@num > 0)
BEGIN
 Set @Result = 'No user created' 
 return @num
END
ELSE
BEGIN
INSERT INTO utable
(
  [username],
  [password]
)
VALUES
(
   @username,
   @password
)
 Set @Result = 'One user created'
 return 0
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

You have a good start, what do you need help with? I have a similar code snippet online at: http://www.daniweb.com/code/snippet1244.html

It is for a winform application but the concept is portable to ASP.NET.

i need to know how to modify the stored procedure, so that i can include the role and not the result. Basically, i shouldn't have any textbox or dropdownlist to indicate role. Once the username and password is entered, the system must search in the database to see if they match. please help.

i get errors like this when i run the system.

ASP.default2_aspx.GetTypeHashCode(): no suitable method found to override. i have highlighted the part that shows the error.

[System.Diagnostics.DebuggerNonUserCodeAttribute()]
   public override int GetTypeHashCode() {            return 1265447914;
    }

help me out please. i am short of time.

okey for the quickstart....

take a default.aspx page....come to design mode..

select website....select asp.net configuration...

next it will open a website...where u can create users...

next when you return you'll find the list of users..

next to list of users...there are roles...

now add roles...and assign users for a suitable role...

okey let me check...now your website have users with roles..

okey good...next you need to implement a formauthentication code

before you do that refresh your solution explorer...

you can see the database added in you app_data folder..

which is totally free...from asp.net..
which is easy...so on desgin page drag 2 textbox and one submit button...

next is on click event write this code...

if (FormsAuthentication.Authenticate(UserName.Text, Password.Text))
Response.Redirect("Your Fav. Page");


well this fastest way to achieve your thing....cos right now
you are sitting on a gas bottle...

hope things work out for you..

best of luck.....that's what they say....!

ive done that, but how to connect the userid textbox and password textbox to the app_Data. At the same time, i need to use datagridview to bring on the data.

my login page involves roles, so once i include:

if (FormsAuthentication.Authenticate(UserName.Text, Password.Text))
Response.Redirect("Your Fav. Page");

will i be able to connect to the roles that is done in the configuration. Please reply. It is urgent.

Will i have to code in the sql database?

Do i have to change any settings in the web.config

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.