Results 1 to 12 of 12

Thread: {urgent} login and passwords

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    39

    {urgent} login and passwords

    Anyone here can guild me how to do login and passwords page in before user get in navigate the web pages? Any sample codes or links can provided?

    I need VB code as well. and i want to ask what is the differences between the login code in html and vb language? Thanks

  2. #2
    Addicted Member Tjoppie's Avatar
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    241

    Re: {urgent} login and passwords

    Hi asp.net,

    I have a table in my db called tusers, I use this way to authenticate them:

    VB Code:
    1. Dim UserID As String = 0
    2.             Dim IsActive As Boolean = False
    3.             Dim IsDisabled As Boolean = False
    4.  
    5.             Dim m As New PtechDLL.DBFunctions
    6.             Dim LoginCon As New SqlConnection(m.DBConnectionstring)
    7.  
    8.             Dim LoginSQL As String = "SELECT UserID, Active, AccDisabled FROM tUser WHERE Username='" & Me.txtUsername.Text & "' AND Password='" & Me.txtPassword.Text & "'"
    9.             Dim Login As New SqlCommand(LoginSQL, LoginCon)
    10.             LoginCon.Open()
    11.             Dim LoginRead As SqlDataReader = Login.ExecuteReader
    12.  
    13.  
    14.             If LoginRead.HasRows = False Then
    15.                 Me.lblErrors.Text = "Invalid Username or password, please try again"
    16.             Else
    17.                 While LoginRead.Read
    18.                     UserID = LoginRead("UserID")
    19.                     IsActive = LoginRead("Active")
    20.                     IsDisabled = LoginRead("AccDisabled")
    21.                 End While
    22.                 Session.Add("UserID", UserID)
    23.                 LoginCon.Close()
    24.                 Response.redirect("~/MyDashboard.aspx")
    25.              End if

    If the user exists in the database, then the datareader will have rows, then I add the userid field in a session variable called "UserID" which I use for the rest of the site for db functions.

    Hope it helps

  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: {urgent} login and passwords

    The difference is, there is no login code in HTML, strictly speaking.

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    39

    Re: {urgent} login and passwords

    erm, what i mean the JavaScript in html page and the javaScript in vb page. Is there any differences?

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

    Re: {urgent} login and passwords

    Yes. The difference is, you don't use javascript in a vb page. You can use Page.RegisterStartupScript or Page.RegisterClientScriptBlock to send javascript to the html that is output though.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: {urgent} login and passwords

    If you do it this way then couldnt the credientials be read and also open to an sql injection attack?
    VB Code:
    1. "SELECT UserID, Active, AccDisabled FROM tUser WHERE Username='" & Me.txtUsername.Text & "' AND Password='" & Me.txtPassword.Text & "'"
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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

    Re: {urgent} login and passwords

    Yep, yep. 4guys has a sample on parameterized queries if you're too lazy to make SPs.

    http://www.4guysfromrolla.com/webtech/092601-1.shtml

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: {urgent} login and passwords

    Thanks, but wasnt that site called 2guys?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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

    Re: {urgent} login and passwords

    Quote Originally Posted by RobDog888
    Thanks, but wasnt that site called 2guys?
    It was until cloning became legal in their country.

  10. #10

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    39

    Re: {urgent} login and passwords

    Dim loginInfo As New MemberDetail
    Dim sqlCommand As SqlCommand
    Dim sqlDataReader As SqlDataReader

    sqlCommand = New SqlCommand("spLogin", sqlConnection)
    sqlCommand.CommandType = CommandType.StoredProcedure
    sqlCommand.Parameters.Add("@Username", SqlDbType.VarChar, 50).Value = Username.Text
    sqlCommand.Parameters.Add("@Password", SqlDbType.VarChar, 50).Value = Password.Text
    sqlCommand.Parameters.Add("@login_ID", SqlDbType.Int).Direction = ParameterDirection.Output


    sqlConnection.Open()
    sqlCommand.ExecuteNonQuery()


    Dim Login_ID As Integer = CInt(sqlCommand.Parameters("@Login_ID").Value)
    sqlConnection.Close()

    If Login_ID > 0 Then
    loginInfo.username = Username.Text
    loginInfo.load = 1
    Session.Add("sessionMember", loginInfo)
    Response.Redirect("reservation.aspx")
    Else
    Dim JSCode As String = ""
    JSCode &= "<script language=""javascript"">"
    JSCode &= "var smessage='please key in the correct USERNAME and PASSWORD';"
    JSCode &= "confirm(smessage)"
    JSCode &= "</script>"
    RegisterStartupScript("myjscode", JSCode)
    Username.Text = ""


    End If
    Here is my login page. Can anyone here kindly tell me how to add Session in every page, so that the user cannot surf the pages inside if cant log in successful.Thanks.

  11. #11

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    39

    Re: {urgent} login and passwords

    any sample codes can provide me arr?

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

    Re: {urgent} login and passwords

    The simplest way is, in the page load of all your pages

    If Session("sessionMember") = "" Then
    Response.Redirect("login.aspx")
    End If

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