Checking a users password

M

Martin

I have the below code that checks to see if a user has a blank password.
That section works. My problem is the else loop. No matter what password I
set for myself, I still get error 3029. My default password is "MARINES" and
I want to force users to change their default password.

My question is can I do it through code?

Thank you for your time and help.


Private Sub Form_Open(Cancel As Integer)

Dim ws As Workspace
Dim myset As Recordset
Dim db As Database
Dim iPerm As Integer
Dim iStud As Integer

On Error Resume Next

Set ws = DBEngine.CreateWorkspace("tempws", CurrentUser(), "")
Debug.Print CurrentUser()
Debug.Print err.number
If err = 0 Then
MsgBox "Your PASSWORD is blank. This will not be tolerated! Your
access to the dbase will be TERMINATED if not fixed NOW.", vbCritical
'users has a blank password
Set db = CurrentDb
Set myset = db.OpenRecordset("tblUsers", dbOpenTable)
myset.Index = "UserName"
myset.Seek "=", CurrentUser()
If myset.NoMatch Then
'Stop No matching record
MsgBox "No Matching UserName record", vbCritical
Else
'Stop found matching record
Debug.Print myset!UserName
myset.Edit
myset!BLANKPASSWORD = -1
myset.Update
End If
Else
' Stop
'users password is not blank
'check to see if it is still the default
Set ws = DBEngine.CreateWorkspace("tempws", CurrentUser(), "MARINES")
Debug.Print err.number, err.Description 'error = 3029 Not a valid
account name or password.
If err = 0 Then
'Stop 'user PASSWORD is still default
MsgBox "Your PASSWORD is still the default. Please change your
password or you will loose your access to the company dbase. Don't know how.
Call 8582 and talk to Mr. Cox.", vbCritical
Else
'Stop 'user has changed their password
MsgBox "Thank you for changing your PASSWORD. ", vbCritical
End If
End If
 
A

AccessVandal via AccessMonster.com

I don't see that you have any error trapping on. Judging from this, I don't
think this error comes from the form' open event.

What's with the "On Error Resume Next" for ignoring errors?
 
M

Martin

If you look at my question "determining if users Password is blank or
standard" posted 8/6/2009 6:54 PM PST, I was told to try On Error Resume Next
to trap this error. This fixed the code from Joan Wild but now I am trying
to get users to change their default password I have assigned through code
and can't seem to determine when their password is "MARINES"

Thank you for your response. Hope you can help me.
 
A

AccessVandal via AccessMonster.com

Martin,

I see.

I have test your code on a sample DB and it does work when I use the default
password "MARINES" (case sensitive) and the message does popup as well as for
blank password and changed password.

Have you select the correct reference for DAO? You may need to disambiguate
the references like

Dim ws As DAO.Workspace
Dim myset As DAO.Recordset
Dim db As DAO.Database

It is not possible to view the user password and there's not a hack that I'm
aware of.

You also need to close the object.

ws.Close
set ws = Nothing
set myset = Nothing
set db = Nothing

after the End If or just before the End Sub of your form's OnOpen event.

Test results:

Set the user password to "MARINES", the error number 3029 will appear if I
use a blank password for the first CreateWorkspace. So is working will exit
smoothly. On the second CreateWorkSpace, if the password is "MARINES", the
error number is 0 and the warning message appeared and it works.

Set the user password to "" (blank), the error number 0 will appear if I use
a blank password for the first CreateWorkspace. It works and the message
appeared and will exit.

Set the user password to "whatever", the error number 3029 will appear for
both CreateWorkSpace and the message box appear "Thank you for changing your
PASSWORD." and it exit smoothly.
 
A

AccessVandal via AccessMonster.com

PS

Sorry forgot about one more thing. You'll need to reset the error, so a
simple one line will do. Just put this line just before the second
CreateWorkSpace like

' Stop
'users password is not blank
'check to see if it is still the default
'add one line to reset error
Err = 0 'add this code here just before the second CreateWorkSpace
Set ws = DBEngine.CreateWorkspace("tempws", CurrentUser(), "MARINES")
Debug.Print err.number, err.Description 'error = 3029 Not a valid
account name or password.

else the code will not work.
 
M

Martin

AccessVandal,

Thank You. Thank You. Thank You. I used your recommendations and my dbase
now works the way I want it to.

Thank you again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top