Code for password change and delete user

  • Thread starter Thread starter Paul Doree
  • Start date Start date
P

Paul Doree

Hi,

I'm working on some changes to the security of an Access XP DB, and need
some code to allow a user to change their password via a simple form (users
are already created and assigned permissions).

I also need a sample of code for deleting a user from the collection of
users.

Can anyone help?

Paul
 
I haven't tested this, it's from a friend. It may work for you:

Public Function ChangePassword(OldPwd As Variant, NewPwd As Variant,
VerifyPwd As Variant)
On Error GoTo Err_ChangePassword

Dim wsp As Workspace, uuser As User
Set wsp = DBEngine.Workspaces(0)
Set uuser = wsp.Users(CurrentUser)

'If OldPwd <> uuser.Password Then
' MsgBox "Your old password is incorrect.", vbOKOnly + vbInformation
'End If

If NewPwd = VerifyPwd Then
uuser.NewPassword OldPwd, NewPwd
Forms!frmSplashPopUp![txtDatePasswordChange] = Date
passwordUpdate
Else
MsgBox "The Passwords do not match. Please try again", vbOKOnly +
vbInformation, "Data Conflict"
End If

Exit Function

Err_ChangePassword:
Select Case Err.Number
Case 3033 'Incorrect Password
Case Else
MsgBox Err.Number, Err.Description, "ChangePassword"
End Select
End Function
 
If you care about consistent case in the passwords, you may want to replace

If NewPwd = VerifyPwd Then

with

If StrComp(NewPwd, VerifyPwd, vbBinaryCompare) <> 0 Then

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Arvin Meyer said:
I haven't tested this, it's from a friend. It may work for you:

Public Function ChangePassword(OldPwd As Variant, NewPwd As Variant,
VerifyPwd As Variant)
On Error GoTo Err_ChangePassword

Dim wsp As Workspace, uuser As User
Set wsp = DBEngine.Workspaces(0)
Set uuser = wsp.Users(CurrentUser)

'If OldPwd <> uuser.Password Then
' MsgBox "Your old password is incorrect.", vbOKOnly + vbInformation
'End If

If NewPwd = VerifyPwd Then
uuser.NewPassword OldPwd, NewPwd
Forms!frmSplashPopUp![txtDatePasswordChange] = Date
passwordUpdate
Else
MsgBox "The Passwords do not match. Please try again", vbOKOnly +
vbInformation, "Data Conflict"
End If

Exit Function

Err_ChangePassword:
Select Case Err.Number
Case 3033 'Incorrect Password
Case Else
MsgBox Err.Number, Err.Description, "ChangePassword"
End Select
End Function
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Paul Doree said:
Hi,

I'm working on some changes to the security of an Access XP DB, and need
some code to allow a user to change their password via a simple form
(users
are already created and assigned permissions).

I also need a sample of code for deleting a user from the collection of
users.

Can anyone help?

Paul
 
Back
Top