Results 1 to 4 of 4

Thread: [02/03] Creating a ASP.NET application, login function.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    26

    [02/03] Creating a ASP.NET application, login function.

    To start off, i ran searches for "login" on multiple forums, including the code sample forums, but could not seem to find any relevant threads. I am not sure if this is the correct forum to post this. I am using Visual stuido .net 2003, and am creating a ASP.NET application. I am trying to make a login function for a web site. It will access the SQL database to check whether the entered userID and password matches, and if it does it will authenticate the user.

    My stored procedure in SQL :
    Code:
    ALTER  proc spSupplierLogin(@UserID varchar(30), @Password varchar(15))
    
    as
    
    if not exists (select * from supplier where UserId = @UserId)
         return -101 //Checks whether the userid exists, if not returns -101
    
    if not exists (select * from supplier where UserId = @UserId and Password = @Password)
    return - 102 //Checks whether the user ID and password matches the ones entered in the database, if not, return -102. I am not sure if this is correct.
    
    if @@ERROR <> 0
    return - 103 //If unexpected error, return -103
    
    return
    The problem is simple.....i do not know how to write the code for authenticating a user, and then determining which user is the one logged in and trying to access restricted data.

    For example, i want user A to be able to login and modify his user account details, but only his user account's details. How would i go around writing the code to check that the account details he is modifying are his own, and not someone else's?

    Secondly i want user A to be able to login and modify certain product information in a catalog, but only the ones he is authorised for. How do i write code so that it checks that user A is authorised to modify details for a certain product? Are there any special SQL tables i need?

    My VB code for the login page :

    VB Code:
    1. Dim connection As New SqlConnection _
    2.         (ConfigurationSettings.AppSettings("ConnectionString"))
    3.         Dim command As New SqlCommand _
    4.         ("spSupplierLogin", connection)
    5.  
    6.         command.CommandType = CommandType.StoredProcedure
    7.         command.Parameters.Add("@UserID", txtLoginID.Text) //User ID entered
    8.         command.Parameters.Add("@Password", txtLoginPass.Text) //Password entered
    9.  
    10.         command.Parameters.Add("@Status", SqlDbType.Int)
    11.         command.Parameters("@Status").Direction = ParameterDirection.ReturnValue
    12.  
    13.         Try
    14.             connection.Open()
    15.             command.ExecuteNonQuery()
    16.  
    17.             Dim status As Integer
    18.             status = command.Parameters("@Status").Value
    19.  
    20.             If status = -101 Then
    21.                 lblLoginMessage.Visible = True
    22.                 lblLoginMessage.Text = "User ID does not exist in the database."
    23.             ElseIf status = -102 Then
    24.                 lblLoginMessage.Visible = True
    25.                 lblLoginMessage.Text = "The entered user ID and password do not match."
    26.             ElseIf status = -103 Then
    27.                 lblLoginMessage.Visible = True
    28.                 lblLoginMessage.Text = "An unexpected error occured during the login process. Please try again or contact support."
    29.               Else
    30.                 Response.Redirect("home.aspx") //If successful will re-direct to the home page
    31.             End If
    32.         Catch ex As Exception
    33.             lblLoginMessage.Visible = True
    34.             lblLoginMessage.Text = ex.Message
    35.         Finally
    36.             connection.Close()
    37.         End Try
    Last edited by Question2; Jan 13th, 2007 at 11:22 AM.

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    26

    Re: [02/03] Creating a ASP.NET application, login function.

    Bump? Doesnt anyone know how to do login functions for a asp.net web application? I thought that would be one of hte most common tasks....

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [02/03] Creating a ASP.NET application, login function.

    It's quite simple. Once you have determined that the user is authenticated, store the user's username in a session variable. On his editing page, access his username from the session variable.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    26

    Re: [02/03] Creating a ASP.NET application, login function.

    In case anyone else sees this, the code for a session variable is session("@ParameterName").

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width