Results 1 to 5 of 5

Change User Password form -- it's writing the ***** mask to the table instead of the new password

  1. #1
    kattatonic1 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Location
    Toronto, Canada
    Posts
    77

    Cool Change User Password form -- it's writing the ***** mask to the table instead of the new password

    Well this made me laugh out loud.

    Usernames and passwords are in tblUsers.

    I have form frmChangePassword with these controls:


    cboUserName
    txtOldPassword
    txtEnterNewPassword
    txtConfirmNewPassword

    It's working great! Except when I set the Input Mask property to Password on the password fields. Instead of writing the new password to the table, Access is writing asterisks to the table! Literally. User types "bob". It displays as *** and goes into table as ***!!!!!! Password on other screens does not accept bob, only literally typing in ***. I had to laugh.

    Ideas? This is my code:

    Code:
    Private Sub cmdChangePassword_Click()
    
    
        'Check User Name exists
        If Me.cboUserName.ListIndex = -1 Then
            MsgBox "Please choose your User Name. If your name is not listed, please contact an administrator.", vbCritical
            Me.cboUserName.SetFocus
            Exit Sub
        End If
                
        'Check old password is correct
        If Me.txtOldPassword <> Me.cboUserName.Column(1) Then
        
            MsgBox "Password is wrong. Try again or contact an adminstrator.", vbOKOnly
            Exit Sub
        End If
                    
        'Check new password entries are not empty
        If IsNull(Me.txtEnterNewPassword) Then
    
    
            MsgBox "Enter New Password cannot be blank.", vbOKOnly
            Exit Sub
        End If
                    
        If IsNull(Me.txtConfirmNewPassword) Then
            
            MsgBox "Confirm New Password cannot be blank.", vbOKOnly
            Exit Sub
        End If
                                        
        'Check new password entries are the same
        If Me.txtEnterNewPassword <> Me.txtConfirmNewPassword Then
        
            MsgBox "Your entries for new password do not match. Try again.", vbOKOnly
            Exit Sub
        End If
                            
        'Update table with new password
        Me!txtConfirmNewPassword.SetFocus
        CurrentDb.Execute "UPDATE tblUsers SET chrPassword = '" & Me.txtConfirmNewPassword.Text & "' WHERE chrUserName = '" & cboUserName & "'"
        MsgBox "Congratulations! Your password has been changed.", vbOKOnly
        
        'return to login
        DoCmd.Close acForm, "frmChangePassword"
        DoCmd.OpenForm "frmLogin"
                                
    End Sub

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,285
    It should still resolve to the correct value in code. Try setting the input mask on the field in the table, not on the form.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    6,654
    I'd say it's because you chose to write the text value of the control instead of its data value:
    Me.txtConfirmNewPassword.Text

    Sometimes they are the same, sometimes not. Drop the .Text
    .Value is the default property of combo's and text boxes, so you can include it or not.
    Last edited by Micron; 03-28-2017 at 02:21 PM. Reason: spelin
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    "Everyone has a photographic memory; some just don't have film." Steven Wright

  4. #4
    kattatonic1 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2013
    Location
    Toronto, Canada
    Posts
    77
    Thanks Bulzie! The unbound text box is displayed though, not the field from the table. :-(

    Micron, thanks! That did work. Hooray!


    For future readers:
    In the meantime a coffee sure helps!
    I also just now tried adding

    Me.txtConfirmNewPassword.InputMask = False

    to the code before the update and that worked. I watched it unmask. The table updated properly. I would have to close the form before the msgbox though so that the user doesn't see it unmask. I went back and happily that didn't permanently turn off the mask on the text box, so that next time user again sees *****.

    I like the solution to remove .Text though and went with that. Less is more.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    6,654
    Just remove the line now that you've got it fixed. IIRC, all property changes to a control, form or report are not permanent unless you either code to switch to design view before applying the property value, or happen to run code against another form that you've (probably accidentally) put in design view first.

    In case you're wondering when else the .Text property does not match the value of the control (.Vaue) it is also different in the BeforeUpdate event. If you think about it:
    - control shows "dog", value is "dog"
    - you enter "cat" in the control and attempt to move off of the control or the form record
    - you have code in its BeforeUpdate and want to validate the entry
    The value property is still dog, the text property is cat. If the validation does not pass, the code might remove cat and revert back to dog.
    So you were not writing "Bob" to the table, but "***"

    Along with these 2 properties, it is possible to know what the control holds for .Value, the visible entry (.Text) and what was there immediately before "dog" (.OldValue).

Please reply to this thread with any new information or opinions.

Similar Threads

  1. User change Password
    By Ekhart in forum Programming
    Replies: 4
    Last Post: 08-11-2016, 02:34 PM
  2. Replies: 4
    Last Post: 12-16-2015, 02:41 PM
  3. Mask Password in InputBox
    By khughes46 in forum Modules
    Replies: 5
    Last Post: 08-04-2015, 11:26 AM
  4. *** mask password in inputbox
    By Kvracing in forum Modules
    Replies: 13
    Last Post: 11-21-2014, 07:22 AM
  5. Replies: 1
    Last Post: 06-22-2012, 08:05 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Tech Forums: Microsoft Office Forums