Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Login.aspx visual studios 2005 vb

Login.aspx visual studios 2005 vb

Scheduled Pinned Locked Moved ASP.NET
tutorialdatabasesecurityhelplearning
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MeterMan
    wrote on last edited by
    #1

    Can someone either tell me how to create a login.aspx file using database authentication in visual studios 2005. or point me to a step-by-step tutorial on doing this please. All the examples i have found use hardcoded username and passwords set in the webconfig file. I want to be able to login enter username and pass and check to see if a valid user and if so then redirect to main page. -sorry for all the questions just tryinig to understand this and this is a place i like to turn to for help- Win32newb "If I wrote a book like I code. It would be one page thick and contain only one word (DUH!)"

    S 1 Reply Last reply
    0
    • M MeterMan

      Can someone either tell me how to create a login.aspx file using database authentication in visual studios 2005. or point me to a step-by-step tutorial on doing this please. All the examples i have found use hardcoded username and passwords set in the webconfig file. I want to be able to login enter username and pass and check to see if a valid user and if so then redirect to main page. -sorry for all the questions just tryinig to understand this and this is a place i like to turn to for help- Win32newb "If I wrote a book like I code. It would be one page thick and contain only one word (DUH!)"

      S Offline
      S Offline
      SABhatti
      wrote on last edited by
      #2

      create a table in database for users.. add users to that table either through enterprise manager or through another web page.. now develop a login page to get username and password from the users.. connect to database and validate user information against table and if it is there then redirect it to your main page otherwise display an error on the login page.. visit this for reference Here[^] -----

      M 1 Reply Last reply
      0
      • S SABhatti

        create a table in database for users.. add users to that table either through enterprise manager or through another web page.. now develop a login page to get username and password from the users.. connect to database and validate user information against table and if it is there then redirect it to your main page otherwise display an error on the login page.. visit this for reference Here[^] -----

        M Offline
        M Offline
        MeterMan
        wrote on last edited by
        #3

        Partial Class Login
        Inherits System.Web.UI.Page
        Dim TestFeed As New Label

        Protected Sub btnOk\_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOk.Click
            If ValidateUser(Username.Text, Password.Text) = True Then
                FormsAuthentication.RedirectFromLoginPage(Username.Text, False)
            Else
                FeedBack.Visible = True
                FeedBack.Text = "We're sorry, but the information you provided" & \_
                    "does not match our database. Please try again."
        
        
        
            End If
        End Sub
        
        
        Protected Function ValidateUser(ByVal uid As String, ByVal pwd As String) As Boolean
            Dim sName, sUser, sPwd As String
            Dim blnValidUser As Boolean
            Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Documents and Settings\\tony.TONYWIN\\My Documents\\Visual Studio 2005\\WebSites\\PedalValveExpense\\pvidb.mdb;User Id=admin;Password=;"
            Dim MySQL As String = "Select userID,BeginDate, ExpenseID from ExpenseReport where userID=@uid"
            Dim MyConn As New System.Data.OleDb.OleDbConnection(strConn)
            Dim objDR As System.Data.OleDb.OleDbDataReader
            Dim Cmd As New System.Data.OleDb.OleDbCommand(MySQL, MyConn)
            MyConn.Open()
            Try
                objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
                While objDR.Read()
        
                    sUser = objDR("userID")
                    FeedBack.Visible = True
                    FeedBack.Text = "whatsup"
                    sPwd = objDR("BeginDate")
                    sName = objDR("ExpenseID")
                End While
        
                If sUser = "" Then
                    blnValidUser = "False"
        
                Else
                    blnValidUser = "True"
                    Session("Name") = sName
                End If
            Catch ex As Exception
                FeedBack.Visible = "true"
                FeedBack.Text = "Sorry Errors have occurred"
            Finally
                ValidateUser = blnValidUser
                MyConn.Close()
            End Try
        End Function
        
        
        Protected Sub Page\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        
        End Sub
        

        End Class

        For some reason the above always gives me a null sUser and in my database I have a value of 1234 for the id thanks for the help by the way Win32newb "If I wrote a book like I code. It would be one page thick and contain only one word (DUH!)"

        M 1 Reply Last reply
        0
        • M MeterMan

          Partial Class Login
          Inherits System.Web.UI.Page
          Dim TestFeed As New Label

          Protected Sub btnOk\_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOk.Click
              If ValidateUser(Username.Text, Password.Text) = True Then
                  FormsAuthentication.RedirectFromLoginPage(Username.Text, False)
              Else
                  FeedBack.Visible = True
                  FeedBack.Text = "We're sorry, but the information you provided" & \_
                      "does not match our database. Please try again."
          
          
          
              End If
          End Sub
          
          
          Protected Function ValidateUser(ByVal uid As String, ByVal pwd As String) As Boolean
              Dim sName, sUser, sPwd As String
              Dim blnValidUser As Boolean
              Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Documents and Settings\\tony.TONYWIN\\My Documents\\Visual Studio 2005\\WebSites\\PedalValveExpense\\pvidb.mdb;User Id=admin;Password=;"
              Dim MySQL As String = "Select userID,BeginDate, ExpenseID from ExpenseReport where userID=@uid"
              Dim MyConn As New System.Data.OleDb.OleDbConnection(strConn)
              Dim objDR As System.Data.OleDb.OleDbDataReader
              Dim Cmd As New System.Data.OleDb.OleDbCommand(MySQL, MyConn)
              MyConn.Open()
              Try
                  objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
                  While objDR.Read()
          
                      sUser = objDR("userID")
                      FeedBack.Visible = True
                      FeedBack.Text = "whatsup"
                      sPwd = objDR("BeginDate")
                      sName = objDR("ExpenseID")
                  End While
          
                  If sUser = "" Then
                      blnValidUser = "False"
          
                  Else
                      blnValidUser = "True"
                      Session("Name") = sName
                  End If
              Catch ex As Exception
                  FeedBack.Visible = "true"
                  FeedBack.Text = "Sorry Errors have occurred"
              Finally
                  ValidateUser = blnValidUser
                  MyConn.Close()
              End Try
          End Function
          
          
          Protected Sub Page\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
          
          End Sub
          

          End Class

          For some reason the above always gives me a null sUser and in my database I have a value of 1234 for the id thanks for the help by the way Win32newb "If I wrote a book like I code. It would be one page thick and contain only one word (DUH!)"

          M Offline
          M Offline
          MeterMan
          wrote on last edited by
          #4

          Figured it out here is the updated code for anyone interested.

          Partial Class Login
          Inherits System.Web.UI.Page
          Dim TestFeed As New Label

          #Region "Code Fired when Button Okay is clicked"
          Protected Sub btnOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOk.Click
          If ValidateUser(Username.Text, Password.Text) = True Then
          FormsAuthentication.RedirectFromLoginPage(Username.Text, False)
          FeedBack.Visible = True
          FeedBack.Text = "You are now authorized please click the link below to proceed"
          'MainPageLink.Visible = True
          Else
          FeedBack.Visible = True
          FeedBack.Text = "We're sorry, but the information you provided" & _
          "does not match our database. Please try again."

              End If
          End Sub
          

          #End Region

          #Region "ValidateUser Function"
          'Version 1.0.1 By Tony Stegall
          'Function: Return Boolean if user is an authorized user
          'PreCondition: User is not logged in and trying to access restricted page
          'User must enter username and password in form
          'PostCondition: Sql query ran based on supplied userid parameter
          'True returned if user is authorized, False if not

          Protected Function ValidateUser(ByVal uid As String, ByVal pwd As String) As Boolean
              Dim blnValidUser As Boolean 'use to determine if user is valid or not 
              Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Documents and Settings\\tony.TONYWIN\\My Documents\\Visual Studio 2005\\WebSites\\PedalValveExpense\\pvidb.mdb;User Id=admin;Password=;"
              Dim MySQL As String = "Select userID,BeginDate, ExpenseID from ExpenseReport where userID=@uid"
              Dim MyConn As New System.Data.OleDb.OleDbConnection(strConn) 'makes a connection to the database based on connection string
              Dim objDR As System.Data.OleDb.OleDbDataReader 'reads the values into memory to reduce server overhead
              Dim Cmd As New System.Data.OleDb.OleDbCommand(MySQL, MyConn) 'executes the actual command to connect to the database 
              Cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@userID", uid)) 'sets up a parameter of userID in the cookie with the userID its encypted by default
              MyConn.Open() ' opens the database connection
              objDR = Cmd.ExecuteReader() ' executes a commmand that actually reads thru the database
          
              Try ' We don't want error out there that would possibly show the user our database struct
                  ' s
          
          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups