Ask Your Question

# How to store password for MySQL?

I want to store the password in odb so that users do not enter the password every time. Answers in this are not helping. Mysql resides on another server which does not allow empty passwords and I also do not want that info displayed on the screen. Since BASE starts without connecting to Mysql (password is asked only if I access something that wants a connection such as a form, a table etc.) my assumption is that a macro assigned somewhere (to open document event?) can be used to start the connection. But how?

edit retag close merge delete

## Comments

@xoristzatziki Your referred to post is not correct. It is here. Also, based upon your comment there, isn't one of your requirements to NOT display the password on the screen as that answer does?

( 2017-10-17 22:01:44 +0200 )edit

## 1 Answer

Sort by » oldest newest most voted

Hello,

This is somewhat unusual but actually found a couple of ways to do this. This of course exposes the password in the macro but not from the IDE. The first way found involves one object at a time so won't go into that here.

The one which worked was a piece of code found here by hanya. Many thanks for this & MRI (and other code) which solved the last piece of the puzzle. Of the three subs presented, only the first is needed with one extra line added at the end:

    Sub AuthenticationTest
dim sURL as string
dim oArgs(0) As New com.sun.star.beans.PropertyValue
dim oDocStatus as object
dim oihandler
oihandler = CreateUnoListener("InteractionHandler_", "com.sun.star.task.XInteractionHandler")
REM This next line from original code
'  sURL = "http://127.0.0.1:8080/requests/status.xml"   '
REM Place URL of your odb here:
sURL = "file:///home/YOUR_DIRECTORY/YOUR_BASE_FILE.odb"
oArgs(0).Name = "InteractionHandler"
oArgs(0).Value = oihandler
oDocStatus = StarDesktop.loadComponentFromURL(sURL, "_default", 0, oArgs)
REM  This is added line
oDocStatus.DataSource.Password = "PASSWORD_FOR_MYSQL"
End Sub


You need to make two changes to the code: the URL location of your odb; password in last line of sub.

Then attach to Open Document event of Base file.

more

## Comments

This partially worked. At least I can now store the password somewhere with a script/batch and load it inside the above SUB. But it does not work for cases the user must change (ex. temporarily) the password. (Also I do not the impact of the code in memory, do I have to set all parameters to nothing?) Thanks anyway. PS.now LO asks every time to save the file before exiting, even after setting params to nothing.

( 2017-10-20 15:20:18 +0200 )edit

As originally stated in the comment on previous post, "Be sure your question is specific on what you are looking for ..". Based upon your question, it works. Not partially. If you want an optional entry, display an input box. If returned empty use the coded PW else use the inputted PW. To eliminate the save document indicator, add oDocStatus.setModified(0) as the last line in the code.

( 2017-10-20 16:33:57 +0200 )edit

And if you don't want to use an input box because it displays the password, create a dialog, use a text box for the password and set the property Password character. Optionally you can also have another text box on the dialog for a different user name.

( 2017-10-20 18:43:52 +0200 )edit

## Stats

Asked: 2017-10-17 21:27:30 +0200

Seen: 67 times

Last updated: Oct 19 '17