Solved

Reset user's password VBA

Posted on 2009-05-14
10
560 Views
Last Modified: 2012-05-07
How can I reset a user's password using VBA. I want my admins to be able to do this through a button click on a form.

I considered:
DBEngine.Workspaces(0).Users(username).NewPassword

But for that to work you need to have the user's old password and you can't just use
DBEngine.Workspaces(0).Users(username).Password
to get it.
0
Comment
Question by:bejhan
  • 4
  • 3
  • 3
10 Comments
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 125 total points
ID: 24387664
<<DBEngine.Workspaces(0).Users(username).NewPassword>>
  You don't need to have the old password, but you do need to be a member of the admins group.
JimD.
0
 
LVL 75
ID: 24387674
Basically this:

Public Function SSF_PwdCtl() As Boolean
   

' all code from experts exchange
    'Dim WS As DAO.Workspace
    Dim sDbName As String
    Dim sPwdOld As String
    Dim sPwdNew As String
    Dim db As DAO.Database

    sDbName = "C:\SomeApp.mdb"
    sPwdOld = InputBox("Old Pwd: ")
    sPwdNew = InputBox("New Pwd:")

   
    Set db = DBEngine.Workspaces(0).OpenDatabase(sDbName, options:=True, readonly:=False, Connect:=";PWD=" & sPwdOld & ";")
   
    db.NewPassword sPwdOld, sPwdNew
   
    MsgBox "Pwd Accepted"
    Set db = Nothing
    SSF_PwdCtl = True

End Function

mx
0
 
LVL 75
ID: 24387680
I assume you are referring to the database password ?

mx
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 57
ID: 24387688
FYI, you don't need the old password and I should have been clearer; when your part of the admins group, you can pass an empty string for either the old or new password argument.
JimD.
0
 
LVL 1

Author Comment

by:bejhan
ID: 24389852
JDettman that's perfect thanks.

Also I was wondering if there is a way to detect if a user's password is blank?
0
 
LVL 75
ID: 24389904
Seems in the code I posted ... if I didn't supply the old password, it did not work.  And ... you certainly have to do that if you are doing it manually ... and I would hope so, otherwise anyone could change the password.  Again, I'm talking about the database password, not ULS.

Are you ?

mx
0
 
LVL 1

Author Comment

by:bejhan
ID: 24389917
Oh sorry MX forgot to reply to you, I was referring to ULS.
0
 
LVL 75
ID: 24389924
ok ... then ignore what I said.

mx
0
 
LVL 57
ID: 24394744
<<Also I was wondering if there is a way to detect if a user's password is blank?>>
  Only way I can think of doing that is to attempt to open a workspace object for that user with a blank password and see if it errors or not.
JimD.
0
 
LVL 1

Author Comment

by:bejhan
ID: 24398553
Ah, I never even thought of that. Works perfect. Previous to this I was making an entry in my user log about setting a password and having to remove it when the password was reset. Not a solution I was happy with.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…

860 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