PC Review


Reply
Thread Tools Rate Thread

Changing password programatically

 
 
Westeral
Guest
Posts: n/a
 
      30th Nov 2009
I am trying to create a simple password manager database for users at my work
site so that they do not keep passwords taped to the screen or in their desk
drawer. The database will be standalone and have a password. When they first
open the database they will change their password. The problem is the code I
have to change it will not work. It runs into a permissions problem even
though I have set the default to open exclusively. The code for the button
and module it uses follow. What am I doing wrong? (I can send the entire
database if needed although it is not totally finished). The database will
be a standalone on each users computer. Thanks in advance.

Private Sub cmdChangePassword_Click()

On Error Resume Next

If Me!txtNewPassword = Me!TxtConfirmNewPassword Then
ChangeUserPassword DBEngine(0).UserName, _
Me!txtCurrentPassword, Me!txtNewPassword

If (Err = 0) Then
MsgBox "Your Password was changed.", _
vbOKOnly + vbInformation, _
"Password Change"

DoCmd.Close acForm, Me.Name
Else
MsgBox "Your password could not be changed." & _
vbCrLf & vbCrLf & _
Error & Err.Number & _
vbCrLf & Err.Description, _
vbOKOnly + vbExclamation, _
"Password Change"

End If
Else
MsgBox "The new passwords do not match."
End If


End Sub


Public Sub ChangeUserPassword(strUser As String, _
strOldPassword As String, strNewPassword As String)
Dim wrk As DAO.Workspace
Dim usr As DAO.User

Set wrk = DBEngine(0)
Set usr = wrk.Users(strUser)

'Change the password
usr.NewPassword strOldPassword, strNewPassword

Set usr = Nothing

Set wrk = Nothing
End Sub

--
Westeral
 
Reply With Quote
 
 
 
 
Arvin Meyer [MVP]
Guest
Posts: n/a
 
      1st Dec 2009
Here's some ancient code that I remember being used in a database to change
the password. A menu option was used yo open a change password form.

The form had three fields: OldPassword, NewPassword and
VerifyNewPassword. It also has two buttons (the code for the click
events is shown below. To display stars rather than the password on
the screen set the Input Mask to Password

' Declarations:

Option Compare Database 'Use database order for string comparisons
Option Explicit

Dim OldPasswordVar As String
Dim NewPasswordVar As String
Dim VerifyVar As String

' Code for Click Event of OK button

Sub OKButton_Click ()

On Error GoTo Err_OKButton_Click


If IsNull(Me!OldPassword) Then
OldPasswordVar = ""
Else
OldPasswordVar = Me!OldPassword
End If

If IsNull(Me!newpassword) Then
MsgBox "Please enter a New Password"
Me!newpassword.SetFocus
Exit Sub
Else
NewPasswordVar = Me!newpassword
End If

If IsNull(Me!Verify) Then
MsgBox "Please verify New Password"
Me!Verify.SetFocus
Exit Sub
Else
VerifyVar = Me!Verify
End If

If NewPasswordVar = VerifyVar Then
DBEngine.Workspaces(0).Users(CurrentUser()).NewPassword
OldPasswordVar, NewPasswordVar
MsgBox "Password changed successfully"
DoCmd Close
Else
MsgBox "Please re-enter new password and verify"
Me!newpassword.SetFocus
Exit Sub
End If


Exit_OKButton_Click:
Exit Sub

Err_OKButton_Click:
Beep
If Err = 3001 Then
MsgBox "You have typed an invalid New Password." & _
vbCrLf & "The maximum length for a password is 14 characters."
ElseIf Err = 3033 Then
MsgBox "Incorrect Old Password. Please try again."
Else
MsgBox Error$ & Err
End If
Resume Exit_OKButton_Click

End Sub


' Code for Click Event of the Cancel Button:

Sub CancelButton_Click ()
DoCmd Close
End Sub

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

Disclaimer: Any code or opinions are offered here as is. Some of that
code has been well tested for number of years. Some of it is untested
"aircode" typed directly into the post. Some may be code from other
authors. Some of the products recommended have been purchased and
used by the author. Others have been furnished by their manufacturers.
Still others have not been personally tested, but have been
recommended by others whom this author respects.

You can thank the FTC of the USA for making this disclaimer necessary.

"Westeral" <(E-Mail Removed)> wrote in message
news:03D0869C-E68E-462A-BCBC-(E-Mail Removed)...
>I am trying to create a simple password manager database for users at my
>work
> site so that they do not keep passwords taped to the screen or in their
> desk
> drawer. The database will be standalone and have a password. When they
> first
> open the database they will change their password. The problem is the code
> I
> have to change it will not work. It runs into a permissions problem even
> though I have set the default to open exclusively. The code for the button
> and module it uses follow. What am I doing wrong? (I can send the entire
> database if needed although it is not totally finished). The database
> will
> be a standalone on each users computer. Thanks in advance.
>
> Private Sub cmdChangePassword_Click()
>
> On Error Resume Next
>
> If Me!txtNewPassword = Me!TxtConfirmNewPassword Then
> ChangeUserPassword DBEngine(0).UserName, _
> Me!txtCurrentPassword, Me!txtNewPassword
>
> If (Err = 0) Then
> MsgBox "Your Password was changed.", _
> vbOKOnly + vbInformation, _
> "Password Change"
>
> DoCmd.Close acForm, Me.Name
> Else
> MsgBox "Your password could not be changed." & _
> vbCrLf & vbCrLf & _
> Error & Err.Number & _
> vbCrLf & Err.Description, _
> vbOKOnly + vbExclamation, _
> "Password Change"
>
> End If
> Else
> MsgBox "The new passwords do not match."
> End If
>
>
> End Sub
>
>
> Public Sub ChangeUserPassword(strUser As String, _
> strOldPassword As String, strNewPassword As String)
> Dim wrk As DAO.Workspace
> Dim usr As DAO.User
>
> Set wrk = DBEngine(0)
> Set usr = wrk.Users(strUser)
>
> 'Change the password
> usr.NewPassword strOldPassword, strNewPassword
>
> Set usr = Nothing
>
> Set wrk = Nothing
> End Sub
>
> --
> Westeral



 
Reply With Quote
 
Westeral
Guest
Posts: n/a
 
      17th Jan 2010
Thanks loads. This will work. Sorry for the late reply but I had decided
not to do the database but have changed my mind. Our Access program at work
(State of Michigan intranet), has security disabled so I cannot set passwords
or change passwords or even lock down the code. I am going to do the
database in Access 2010 and then implement with Runtime. The state internet
is going to start using Access 2003 this year so using Access 2010 runtime
will keep it secure enough for our intranet as nobody has Access 2010 to
access it otherwise. I know a password database is not the most secure but
it will be much better than the way our users currently keep their passwords,
on a piece of paper inside their desk drawer, on their calendar, etc. Again
thanks.
--
Westeral


"Arvin Meyer [MVP]" wrote:

> Here's some ancient code that I remember being used in a database to change
> the password. A menu option was used yo open a change password form.
>
> The form had three fields: OldPassword, NewPassword and
> VerifyNewPassword. It also has two buttons (the code for the click
> events is shown below. To display stars rather than the password on
> the screen set the Input Mask to Password
>
> ' Declarations:
>
> Option Compare Database 'Use database order for string comparisons
> Option Explicit
>
> Dim OldPasswordVar As String
> Dim NewPasswordVar As String
> Dim VerifyVar As String
>
> ' Code for Click Event of OK button
>
> Sub OKButton_Click ()
>
> On Error GoTo Err_OKButton_Click
>
>
> If IsNull(Me!OldPassword) Then
> OldPasswordVar = ""
> Else
> OldPasswordVar = Me!OldPassword
> End If
>
> If IsNull(Me!newpassword) Then
> MsgBox "Please enter a New Password"
> Me!newpassword.SetFocus
> Exit Sub
> Else
> NewPasswordVar = Me!newpassword
> End If
>
> If IsNull(Me!Verify) Then
> MsgBox "Please verify New Password"
> Me!Verify.SetFocus
> Exit Sub
> Else
> VerifyVar = Me!Verify
> End If
>
> If NewPasswordVar = VerifyVar Then
> DBEngine.Workspaces(0).Users(CurrentUser()).NewPassword
> OldPasswordVar, NewPasswordVar
> MsgBox "Password changed successfully"
> DoCmd Close
> Else
> MsgBox "Please re-enter new password and verify"
> Me!newpassword.SetFocus
> Exit Sub
> End If
>
>
> Exit_OKButton_Click:
> Exit Sub
>
> Err_OKButton_Click:
> Beep
> If Err = 3001 Then
> MsgBox "You have typed an invalid New Password." & _
> vbCrLf & "The maximum length for a password is 14 characters."
> ElseIf Err = 3033 Then
> MsgBox "Incorrect Old Password. Please try again."
> Else
> MsgBox Error$ & Err
> End If
> Resume Exit_OKButton_Click
>
> End Sub
>
>
> ' Code for Click Event of the Cancel Button:
>
> Sub CancelButton_Click ()
> DoCmd Close
> End Sub
>
> --
> Arvin Meyer, MCP, MVP
> http://www.datastrat.com
> http://www.mvps.org/access
> http://www.accessmvp.com
>
> Disclaimer: Any code or opinions are offered here as is. Some of that
> code has been well tested for number of years. Some of it is untested
> "aircode" typed directly into the post. Some may be code from other
> authors. Some of the products recommended have been purchased and
> used by the author. Others have been furnished by their manufacturers.
> Still others have not been personally tested, but have been
> recommended by others whom this author respects.
>
> You can thank the FTC of the USA for making this disclaimer necessary.
>
> "Westeral" <(E-Mail Removed)> wrote in message
> news:03D0869C-E68E-462A-BCBC-(E-Mail Removed)...
> >I am trying to create a simple password manager database for users at my
> >work
> > site so that they do not keep passwords taped to the screen or in their
> > desk
> > drawer. The database will be standalone and have a password. When they
> > first
> > open the database they will change their password. The problem is the code
> > I
> > have to change it will not work. It runs into a permissions problem even
> > though I have set the default to open exclusively. The code for the button
> > and module it uses follow. What am I doing wrong? (I can send the entire
> > database if needed although it is not totally finished). The database
> > will
> > be a standalone on each users computer. Thanks in advance.
> >
> > Private Sub cmdChangePassword_Click()
> >
> > On Error Resume Next
> >
> > If Me!txtNewPassword = Me!TxtConfirmNewPassword Then
> > ChangeUserPassword DBEngine(0).UserName, _
> > Me!txtCurrentPassword, Me!txtNewPassword
> >
> > If (Err = 0) Then
> > MsgBox "Your Password was changed.", _
> > vbOKOnly + vbInformation, _
> > "Password Change"
> >
> > DoCmd.Close acForm, Me.Name
> > Else
> > MsgBox "Your password could not be changed." & _
> > vbCrLf & vbCrLf & _
> > Error & Err.Number & _
> > vbCrLf & Err.Description, _
> > vbOKOnly + vbExclamation, _
> > "Password Change"
> >
> > End If
> > Else
> > MsgBox "The new passwords do not match."
> > End If
> >
> >
> > End Sub
> >
> >
> > Public Sub ChangeUserPassword(strUser As String, _
> > strOldPassword As String, strNewPassword As String)
> > Dim wrk As DAO.Workspace
> > Dim usr As DAO.User
> >
> > Set wrk = DBEngine(0)
> > Set usr = wrk.Users(strUser)
> >
> > 'Change the password
> > usr.NewPassword strOldPassword, strNewPassword
> >
> > Set usr = Nothing
> >
> > Set wrk = Nothing
> > End Sub
> >
> > --
> > Westeral

>
>
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Programatically changing options =?Utf-8?B?c25pYnJpbA==?= Microsoft Outlook Program Addins 4 17th Jul 2007 06:25 PM
Changing a Service Account Password programatically Adrian Dev Microsoft C# .NET 0 8th Aug 2006 05:30 PM
programatically changing your Access password Brad Pears Microsoft Access Form Coding 5 21st Jul 2005 11:39 PM
programatically changing the category =?Utf-8?B?Q2hhcmxpZQ==?= Microsoft Outlook Form Programming 1 20th May 2005 06:19 PM
Tab Control - Changing Page Programatically Keith Microsoft Access Form Coding 2 18th Sep 2003 09:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:06 AM.