By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,510 Members | 1,821 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,510 IT Pros & Developers. It's quick & easy.

asp.net problem...

P: 10
hi...learning asp.net ...
have a problem...

created two pages..
one hs a username and password...
second page is a redirect from button click in first page...
need to authenticate the econd page...
please help with the codes in C#.net..
Apr 26 '07 #1
Share this Question
Share on Google+
4 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
This question is being moved to the .NET forum.

ADMIN
Apr 26 '07 #2

Frinavale
Expert Mod 5K+
P: 9,731
hi...learning asp.net ...
have a problem...

created two pages..
one hs a username and password...
second page is a redirect from button click in first page...
need to authenticate the econd page...
please help with the codes in C#.net..

Hi there Ahsan,

Have you thought about how you are going to authenticate the user's credentials? (Thought about how to verify the user name and password are valid?)

The most common way to validate user credentials is:
In your button click on the first page you take the user name and password provided and check them against the values you have stored in a database.

Cheers!

-Frinny
Apr 26 '07 #3

P: 37
Hi,

Benefits of Forms-Based Authentication

1. Developer can configure Forms-based authentication for various parts of the website differ ently, because the Web.config is a hierarchical XML document.
2. Administrator and developer can change the authentication scheme quickly and easily in the Web.config file
3. Administration is centralized because all the authentication entries are in one place - Web.config file.

Authenticating Users with a Database Table

To support a custom user registration system, we need to store usernames and passwords in a database table, so that we can make this as a scalable solution.

Create a table in the FinAccounting Database and named as UserTable. We can create a table using SQL Query Analyzer or Enterprise Manager. The command to do this task is given below.
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE UserTable
  2. (
  3. u_id INT NULL IDENTITY,
  4. u_username VARCHAR(20),
  5. u_password VARCHAR(20)
  6. )
We need to place the following code in the login.aspx (HTML view window) as shown below.
Expand|Select|Wrap|Line Numbers
  1. <hr>
  2. <asp:HyperLink ID="lnkRegister" Text="Click here to Register!" Runat="server" />
  3. of the UserTable database table. We need to write the following code in the login.aspx.
  4.  
  5. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  6.  
  7. Dim myconnection As SqlConnection
  8. Dim myCommand As SqlCommand
  9. Dim myparameter As SqlParameter
  10. Dim intResult As Integer
  11.  
  12. myconnection = New SqlConnection(“Data Source=sys1;Integrated Security=SSPI;Initial Catalog=FinAccounting”)
  13. myconnection.Open()
  14. Dim strSQL As String
  15. strSQL = “SELECT * FROM UserTable WHERE u_username = @Username AND u_password = @Password”
  16.  
  17. Dim oCommand As New SqlCommand(strSQL, myconnection)
  18. ‘ Add the parameters for the query.
  19. oCommand.Parameters.Add(“@Username”, txtUsername.Text.Trim())
  20. oCommand.Parameters.Add(“@Password”, txtPassword.Text.Trim())
  21. Dim dr As SqlDataReader
  22. dr = oCommand.ExecuteReader(CommandBehavior.CloseConnection)
  23.  
  24. Try
  25.     If dr.Read() Then
  26.         Response.Write(“We’re logged in”)
  27.         FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, False)
  28.     Else
  29.         ‘Username and password DO NOT match
  30.         Response.Write(“Login failed”)
  31.     End If
  32. Catch ex As Exception
  33. Finally
  34.     dr.Close()
  35.     myconnection.Close()
  36.     myconnection.Dispose()
  37.     oCommand.Dispose()
  38. End Try
  39. End Sub
  40.  
[Link Removed]
Apr 27 '07 #4

P: 10
thank u..will try...but wanted the code in C#..wil try to convert it..
Apr 27 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.