Solved

Add User / Password to ADO Connection String

Posted on 2002-04-01
6
383 Views
Last Modified: 2012-06-22
Hello,

VB6(sp5) ADO

How do I add a User and Password to an ADO conncetion string to open a MS Access databse? Any pitfalls I should be aware of?

Also, is there a way for a person to see this password when the application is comipled into an .exe file?


Thanks,

ADawn
0
Comment
Question by:ADawn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 18

Expert Comment

by:mdougan
ID: 6910197
Is it the "Database Password" you are refering to, or is it the password associated with a particular user?  In Access, you can go into the section that allows you to define users and give them passwords.  But, there is also a place where you can go to assign a database password that is separate from the user passwords, and the syntax is different, I think.

If it's the database password, then simply try putting

;Password=xyz;

in your connect string.

You are correct in being concerned about someone being able to possibly browse the password in the EXE.  Most String literals are kept in a particular spot in the EXE and anyone can browse the EXE in a hex editor and read many of the string literals.

One technique I use is to lightly encrypt the string literal and then de-encrypt it when I actually go to use it.  So, your code might look like:

Const CONN_STRING = "!@%$#ft^....."

CN.ConnectString = DeEncrypt(CONN_STRING)

The way that I lightly encrypt/de-encrypt strings is to have a routine that converts each letter of the string into it's ASCII value, and then it subtracts some constant number, like 8 or 9 from the ascii value, then converts the result back to a character.  To de-Encrypt something, you simply do the same thing, but add the same constant number to the ASCII value.

So, I usually have a procedure called Encrypt that takes a boolean flag for whether you're trying to encrypt or de-encrypt, and depending on the flag, you either subtract or add the constant number respectively.

I said that this lightly encrypts the text.  That means that if any casual user was browsing the EXE they wouldn't be able to read any recognizable text.  If someone was pretty knowledgeable about cryptography, they might be able to find the string associated with your connect string, and then one of the first things they would try is this simple ascii manipulation.  So, if you're guarding important secrets this isn't the best approach.  But, if you want to foil 99.8 percent of your users out there, I think this works fine.
0
 
LVL 18

Accepted Solution

by:
mdougan earned 20 total points
ID: 6910220
Here is an example of the Encrypt routine:

Private Sub Command1_Click()
Static bEncrypt As Boolean

    If Not bEncrypt Then
        bEncrypt = True
    Else
        bEncrypt = False
    End If
   
    Text1.Text = Encrypt(Text1.Text, bEncrypt)

End Sub

Public Function Encrypt(ByVal sSource As String, bEncrypt As Boolean)
    Dim Letter As String
    Dim i As Integer
    For i = 1 To Len(sSource)
        Letter = Mid$(sSource, i, 1)
        If bEncrypt Then
            Mid$(sSource, i, 1) = Chr(Asc(Letter) - 7)
        Else
            Mid$(sSource, i, 1) = Chr(Asc(Letter) + 7)
        End If
    Next i
    Encrypt = sSource
End Function
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 6910295
'connection to secure database
Dim Cnn As ADODB.Connection
Dim Rst As ADODB.Recordset

'In the place where you want to establish your connection, such
'as the Initialize event of a class module, enter the following:

Dim strConnect As String
Set Cnn = New ADODB.Connection

'Substitute your own User IDs, Password, Data Source, and System
'database in the connection string below
    strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Password=MyPassword;User ID=Administrator;" & _
        "Data Source=C:\AccessDBs\DB1.mdb;" & _
        "Persist Security Info=True;" & _
        "Jet OLEDB:System database=C:\AccessDBs\system.mdw"

    With Cnn
        .CursorLocation = adUseClient
        .Open strConnect
    End With
   
    Set Rst = New ADODB.Recordset
    Rst.ActiveConnection = Cnn      
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Expert Comment

by:humbk2002
ID: 6912232
try out this code,but you should first have a table with the password and username fileds in your database.The username or password you enter should be the one in the database.

Private Sub Login_Click()
Dim found As Boolean
On Error GoTo errhandler

found = False


If (Username <> "") And (Password <> "") Then
Set DB = OpenDatabase("Yuor database.mdb")
Set RS = DB.OpenRecordset("Your table")
End If
Do While (RS!Password <> "") And (Not found)
If (RS!Username = Username.Text) And (RS!Password = Password.Text) Then
found = True
Else
RS.MoveNext
End If
Loop
If found Then

Login.Visible = False
Here load the form you are logging in
Load YourForm
YourForm.Show
End If
Set RS = Nothing

Exit Sub

errhandler:
'if password or username not in db then error message is  displayed
If Err = 3021 Then
MsgBox "Incorrect Username or Password,Try one's the system recognises..." & "Consult system administrator if having problem logging on...", vbExclamation
Else
Exit Sub
End If
End Sub



0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7017055
8 open questions, all of which need your attention.  ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20140167.html
http://www.experts-exchange.com/questions/Q.20141981.html
http://www.experts-exchange.com/questions/Q.20253108.html
http://www.experts-exchange.com/questions/Q.20256316.html
http://www.experts-exchange.com/questions/Q.20277938.html
http://www.experts-exchange.com/questions/Q.20283655.html
http://www.experts-exchange.com/questions/Q.20301283.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20217848.html

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0
 

Author Comment

by:ADawn
ID: 7036896
I'll try this...
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question