Results 1 to 3 of 3

Thread: Password and Login

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2001
    Location
    South England
    Posts
    38

    Password and Login

    Hi Guys, does anyone have an example of some VB code and SQL where when a user is trying to LOGIN with his password and username, it compaires it in the database and then allows them to be logged in, if you know what i mean.

    SQL = "UPDATE register " _
    & " SET password = " & sPassword _
    & " , username = " & sUsername _
    & " WHERE MessageIndex = " & iIndex

    would this be correct or not as it seems wrong to me.

    Charlie
    Last edited by charliemancini; Aug 16th, 2001 at 04:44 AM.

  2. #2
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    If you are using access you could try something like:

    VB Code:
    1. SQL = "Select 1 " & _
    2.           "From register " & _
    3.           "Where username='" & sUsername & "' " & _
    4.           "And password = '" & sPassword & "'"
    5.  
    6. 'ConnObject is you connection to the database
    7. rs.open SQL, ConnObject, adOpenStatic, adLockReadOnly
    8.  
    9. 'If no records returned then the login failed
    10. If rs.recordcount = 0 then
    11.         MsgBox "Login Attemp Failed."
    12.         Exit Sub
    13. 'Login was successfull
    14. Else
    15.         'Continue w/ processing
    16. End If

    If you are using SQL Server, create a connection string to the database you are trying to connect to and perform some error trapping to make sure the user is a valid user:
    VB Code:
    1. Dim conn as Connection
    2. Dim ConnStr as String
    3.  
    4. ConnStr = "Provider=SQLOLEDB;Server=YourServer;"
    5. ConnStr = ConnStr & "Database=YourDatabase;UID=" & sUserName
    6. ConnStr = ConnStr & ";PWD=" & sPassword
    7.  
    8. set conn = new connection
    9. On Error Goto ErrHandler
    10.  
    11. Conn.Open connStr
    12.  
    13. Exit Sub
    14. ErrHandler:
    15.    If Err = -2147217843 Then
    16.             msgbox "Verify UserName and Password"
    17.             exit sub
    18.    End If

    Hope this helps.

    Chris
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2001
    Location
    South England
    Posts
    38
    I'm sure it will, thanks Chris

    p.s. i'm doing it in VB and Access


    Charlie

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