Results 1 to 9 of 9

Thread: SQLServer Validate Login

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    Carolina, Puerto Rico, USA
    Posts
    227

    SQLServer Validate Login

    Hello,

    I have been looking around for this information, but did not found anything.

    I want to validate the login of an user from Visual Basic to SQL Server, the user enters the login information in the application, then I send that information over to the database to verify it exist and is valid. Is there a way to do that?

    Thanks in advance!
    NievesJ

  2. #2
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    You can try to create a connection to the database using the user's login credentials:
    VB Code:
    1. Public Function VerifyLogin(sUID As String, sPWD As String) As Boolean
    2. On Error Goto errHandler
    3.     Dim oCon  As ADODB.Connection
    4.     Dim sConStr As String
    5.  
    6.     sConStr = "Provider=SQLOLEDB.1;" & _
    7.               "Server=[b]YourSQLServer[/b];" & _
    8.               "Initial Catalog=[b]YourDBName[/b];" & _
    9.               "UID=" & sUID & ";" & _
    10.               "PWD=" & sPWD & ";"
    11.  
    12.  
    13.     Set oCon = New ADODB.Connection
    14.     With oCon
    15.         .Open sConStr
    16.         VerifyLogin = True
    17.         .Close
    18.     End With
    19.     Set oCon = Nothing
    20.     Exit Function
    21. errHandler:
    22.     Set oCon = Nothing
    23.     VerifyLogin = False
    24. End Function
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    Carolina, Puerto Rico, USA
    Posts
    227
    Nice!!

    Now I have another problem, the domain accounts are not validating, only the accounts created on SQL Server works, the autehtication on the server is SQL and Windows......
    NievesJ

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    Domain accounts do not use the same connection strings as SQL Authentication accounts. Something more like this...

    VB Code:
    1. sConStr = "Provider=SQLOLEDB.1;" & _
    2.               "Integrated Security=SSPI;" & _
    3.               "Server=YourSQLServer;" & _
    4.               "Initial Catalog=YourDBName;"

    BTW - Mixing authentication types - why?? MS recommends Win2K authentication - not SQL authentication. Why have you made your choice??

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    Carolina, Puerto Rico, USA
    Posts
    227
    Originally posted by szlamany
    Domain accounts do not use the same connection strings as SQL Authentication accounts. Something more like this...

    VB Code:
    1. sConStr = "Provider=SQLOLEDB.1;" & _
    2.               "Integrated Security=SSPI;" & _
    3.               "Server=YourSQLServer;" & _
    4.               "Initial Catalog=YourDBName;"

    BTW - Mixing authentication types - why?? MS recommends Win2K authentication - not SQL authentication. Why have you made your choice??
    But there's no username and pass for that connection string?, it authenticates with the logged account?, thats not what I want.

    BTW - Mixing authentication types - why?? MS recommends Win2K authentication - not SQL authentication. Why have you made your choice??
    Dont know, this is the first time I wirk with SQL Server.
    NievesJ

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    The whole point of Win2K is integrated security.

    A person logs into the PC once - and everything authenticates from that moment.

    When you get into OUTLOOK on your PC, it doesn't ask for a username/password.

    Having a person type a username and password at application launch time, and sending that in "clear text" around a network is a security hole.

    So, when using integrated security, the domain/username of the person at logon time is used at SQL connection time - all automatically. Very nice and neat.

    I'm sure we could start a debate here about the merits of both types of authentication.

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    What we did on our login screen is to have a check box "Use Windows Login" If they user checks it, we disable the UserName and Password fields. It also then allows us to build the right kind of connection string to authenticate with.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    Here's some code from our EstablishConnection FUNCTION...

    VB Code:
    1. If strDriver = "" Then
    2.         strDriver = "SQLOLEDB"
    3.     End If
    4.    
    5.     'Create a connection to the database
    6.     Set gCn = New ADODB.Connection
    7.    
    8.     gCn.Provider = strDriver
    9.     gCn.Properties("Data Source").Value = strServer
    10.     gCn.Properties("Initial Catalog").Value = strDatabase
    11.     If gstrUser <> "" Then
    12.         gCn.Properties("User Id").Value = gstrUser
    13.         gCn.Properties("Password").Value = gstrPassWord
    14.     Else
    15.         gCn.Properties("Integrated Security").Value = "SSPI"
    16.     End If
    17.    
    18.     gCn.CommandTimeout = 300
    19.     gCn.Open
    20.    
    21.     'Check the connection state
    22.     If gCn.State = adStateOpen Then
    23.         EstablishConnection = True
    24.     Else
    25.         EstablishConnection = False
    26.     End If

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    Carolina, Puerto Rico, USA
    Posts
    227
    Originally posted by szlamany
    The whole point of Win2K is integrated security.

    A person logs into the PC once - and everything authenticates from that moment.

    When you get into OUTLOOK on your PC, it doesn't ask for a username/password.

    Having a person type a username and password at application launch time, and sending that in "clear text" around a network is a security hole.

    So, when using integrated security, the domain/username of the person at logon time is used at SQL connection time - all automatically. Very nice and neat.

    I'm sure we could start a debate here about the merits of both types of authentication.
    That would work in an environment that all computers are in the Domain, that is not the case here. Oh well, I guell I have to enter all logins manually...
    NievesJ

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