Page 1 of 1

How could I change mdb password?

Posted: Fri Mar 13, 2009 12:50 am
by Mahmoud
Dear All,

I'm new to PureBasic and I decided to develop an application that needs secure database, so i decided to use Access database instead of SQlite, and finally i used the MDB_Lib by Paul Leischow because its easy, but i need to know how to add a user and password to the database, i tried different ways such as:

Code: Select all

DatabaseQuery(db,"ALTER DATABASE PASSWORD newpassword NULL")
and
DatabaseQuery(db,"ALTER USER user PASSWORD newpassword NULL")
But no way, then i tried to add a password from the Access itself and connect to the database through the MDB_Lib and it succeeded, then i tried again to use the above codes, but still no way, can any body find me a way to set or change a user and password?

Here my code:

Code: Select all

;/ Created with PureVisionXP v4.00
;/ Thu, 08 Jun 2006 19:22:42
;/ by Reel Media Productions

XIncludeFile "Demo_Constants.pb"
XIncludeFile "Demo_Windows.pb"

Global db.l
curdir.s=GetCurrentDirectory()
idx=1
total=3

Procedure Form_Fill(id.l)
  qry.s="Select name,phone from Info where id="+Str(id)
  If DatabaseQuery(db,qry)
    If NextDatabaseRow(db)
      SetGadgetText(#Gadget_Main_Name,GetDatabaseString(db,0))
      SetGadgetText(#Gadget_Main_Phone,GetDatabaseString(db,1))
    EndIf
  EndIf
EndProcedure

;MDB_Create(curdir+"Test")
db=MDB_Connect(curdir,"Test","","currpassword")
If db=0
  MessageRequester("Error","Could Not Connect to Database",#MB_ICONERROR)
  End
EndIf

qry.s="Create table Info(id autoincrement,name text(100),phone text(50),"
qry+"constraint Info unique(id));"
If DatabaseQuery(db,qry) 
  DatabaseQuery(db,"ALTER DATABASE PASSWORD newpassword currpassword")
  DatabaseQuery(db,"Insert into Info(name,phone)values('Paul','555-1234')")
  DatabaseQuery(db,"Insert into Info(name,phone)values('Fred','555-0098')")
  DatabaseQuery(db,"Insert into Info(name,phone)values('Joey','555-4455')")
EndIf



;- Main Loop
If Window_Main()
  Form_Fill(idx)
  
  quitMain=0
  Repeat
    EventID  =WaitWindowEvent()
    MenuID   =EventMenu()
    GadgetID =EventGadget()
    WindowID =EventWindow()

    Select EventID
      Case #PB_Event_CloseWindow
        If WindowID=#Window_Main
          quitMain=1
        EndIf


      Case #PB_Event_Gadget
        Select GadgetID
          Case #Gadget_Main_Back
            idx-1
            If idx<1
              idx=1
            EndIf
            Form_Fill(idx)
            
          Case #Gadget_Main_Next
            idx+1
            If idx>total
              idx=total
            EndIf
            Form_Fill(idx)
            
        EndSelect

    EndSelect
  Until quitMain
  CloseWindow(#Window_Main)
EndIf

CloseDatabase(db)
MDB_Disconnect("Test")
End
Sorry for my bad English... ;))

Thanks,

Posted: Fri Mar 13, 2009 4:38 am
by Rook Zimbabwe
Your syntax is wrog unless you are simply trying to hack a database... hacking is BAD and frowned upon here!
ALTER DATABASE PASSWORD newpassword oldpassword

ALTER USER user PASSWORD newpassword oldpassword
You have to include the old password in the statement or it won't work!

Posted: Fri Mar 13, 2009 5:35 am
by Mahmoud
Rook Zimbabwe wrote:Your syntax is wrog unless you are simply trying to hack a database... hacking is BAD and frowned upon here!
ALTER DATABASE PASSWORD newpassword oldpassword

ALTER USER user PASSWORD newpassword oldpassword
You have to include the old password in the statement or it won't work!
I don't need to hack a database, but in first code part I tried to set a password for a non-passworded database, so I set the old password to "NULL" as I found in some forums, but this way didn't succeed, then I tried to set a password from Access 2007 and change it through my second code part, but also didn't succeed.

And the syntax you wrote is the same as I used in the second part, so I need a way to set a password or change old password.