Results 1 to 10 of 10

Thread: The password supplied is not correct... It is!
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular albertc30's Avatar
    Join Date
    May 2012
    Location
    Norfolk
    Posts
    969
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question The password supplied is not correct... It is!

    Hi all.

    I have a userform that allows me to type in a username and a password.

    This then is checked to a hidden sheet and if found it opens if not it returns an error as per bellow code;

    Code:
    Private Sub cmBtnLogin_Click()
    
    
    Dim iFoundPass As Integer
    On Error Resume Next
    With Sheets("UsersHide").Range("UserNames")
    
    
       iFoundPass = .Find(What:=txtBoxUserName, After:=.Cells(1, 1), LookIn:=xlValues, LookAt _
            :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False).Row
    End With
    On Error GoTo 0
    
    
    If iFoundPass = 0 Then
       SomethingWrong
          Exit Sub
    End If
    
    
    If Sheets("UsersHide").Cells(iFoundPass, 2) <> txtBoxPassword Then
       SomethingWrong
          Exit Sub
    End If
    
    
    Sheets("Invoice").Unprotect Password:="******"
        
    Sheets("Invoice").Range("CurrentUser") = txtBoxUserName
    
    
    Sheets("Invoice").Protect Password:="*******"
    
    
    Unload Me
    
    
    Application.Visible = True
    
    
    End Sub
    This has always worked with no issues and today, it now behaves differently even though that code was never touched.

    In fact, when I try to open the spreadsheet again after the error, it now tells me the page is already opened!

    In fact, if I enter the wrong password I get the wrong message error!

    The error I am now getting is the following;

    Run-Time error '1004':
    The password you supplied is not correct. Verify that the CAPS LOCK key is off and be sure to use the correct capitalization.

    Also, with a top spec PC i5 with 16GB RAM why is VBA telling me no memory or low memory?

    It's all happening at once.

    Any help is really appreciated.

    Thanks.
    Many thanks for all the help, much appreciated.

    Regards,
    Albert

    Reminder
    Remember to use code tags people.

  2. #2
    Board Regular Kenneth Hobson's Avatar
    Join Date
    Feb 2007
    Location
    Tecumseh, OK
    Posts
    3,079
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default Re: The password supplied is not correct... It is!

    It is better to Set the find equal to a range rather than an integer. Even it it did work with an integer, rows should always be dimmed as Long to be on the safe side.

    e.g.
    Code:
    Private Sub cmBtnLogin_Click()
      Dim rFoundPass As Range
      
      With Sheets("UsersHide").Range("UserNames")
        Set rFoundPass = .Find(What:=txtBoxUserName, After:=.Cells(1, 1), LookIn:=xlValues, LookAt _
          :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
          False)
      End With
      
      If rFoundPass Is Nothing Then
         SomethingWrong
          Exit Sub
      End If
      
      If Sheets("UsersHide").Cells(rFoundPass.Row, 2) <> txtBoxPassword Then
         SomethingWrong
          Exit Sub
      End If
      
      Sheets("Invoice").Unprotect Password:="******"
      Sheets("Invoice").Range("CurrentUser") = txtBoxUserName
      Sheets("Invoice").Protect Password:="*******"
      
      Unload Me
      Application.Visible = True
    End Sub

  3. #3
    Board Regular albertc30's Avatar
    Join Date
    May 2012
    Location
    Norfolk
    Posts
    969
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: The password supplied is not correct... It is!

    Hi Kenneth.

    I have just tried your code and it still returns the same error.

    Much appreciated for your help and apologies for the late reply.

    I'm going to have to break my head with this one.

    Not once did I even touched the code for this and it's going **** up now!

    Cheers.
    Many thanks for all the help, much appreciated.

    Regards,
    Albert

    Reminder
    Remember to use code tags people.

  4. #4
    Board Regular
    Join Date
    Apr 2010
    Posts
    167
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Re: The password supplied is not correct... It is!

    Put a breakpoint on this line...


    Code:
    If Sheets("UsersHide").Cells(iFoundPass, 2) <> txtBoxPassword Then

    when you get to this breakpoint in your code, drop down to your immediate window and test those variables and see what they are.

    type these lines into the immediate window and hit enter...

    ?Sheets("UsersHide").Cells(iFoundPass, 2)
    ?txtBoxPassword
    ?txtBoxPassword = Sheets("UsersHide").Cells(iFoundPass, 2)

    Please share the results
    Last edited by Steve_; Jul 31st, 2019 at 02:20 PM.

  5. #5
    Board Regular albertc30's Avatar
    Join Date
    May 2012
    Location
    Norfolk
    Posts
    969
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: The password supplied is not correct... It is!

    Oh dear...

    This is a bit above my pay grade, lol...

    I'll give it a try.

    Cheers.
    Many thanks for all the help, much appreciated.

    Regards,
    Albert

    Reminder
    Remember to use code tags people.

  6. #6
    Board Regular Kenneth Hobson's Avatar
    Join Date
    Feb 2007
    Location
    Tecumseh, OK
    Posts
    3,079
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default Re: The password supplied is not correct... It is!

    If it is a case issue, put lcase() around the found password and the texbox's password. That way, your equality check will always work. Otherwise, your worksheet found password case must match the textbox's case.

    Since these are passwords, it may not be advisable to show results in this forum unless you obfuscate them.

    For the case check, the VBE Immediate Window view of the debug.print values can be done this way after running the code.
    Code:
    Private Sub cmBtnLogin_Click()
      Dim rFoundPass As Range
      
      With Sheets("UsersHide").Range("UserNames")
        Set rFoundPass = .Find(What:=txtBoxUserName, After:=.Cells(1, 1), LookIn:=xlValues, LookAt _
          :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
          False)
      End With
      
      If rFoundPass Is Nothing Then
         SomethingWrong
          Exit Sub
      End If
      
      Debug.Print rFoundPass, rFoundPass.row
      Debug.Print Sheets("UsersHide").Cells(rFoundPass.Row, 2), txtBoxUserName
      Debug.Print lcase(Sheets("UsersHide").Cells(rFoundPass.Row, 2)), lcase(txtBoxUserName)
    
      If Sheets("UsersHide").Cells(rFoundPass.Row, 2) <> txtBoxPassword Then
         SomethingWrong
          Exit Sub
      End If
      
      Sheets("Invoice").Unprotect Password:="******"
      Sheets("Invoice").Range("CurrentUser") = txtBoxUserName
      Sheets("Invoice").Protect Password:="*******"
      
      Unload Me
      Application.Visible = True
    End Sub
    Last edited by Kenneth Hobson; Jul 31st, 2019 at 02:42 PM.

  7. #7
    Board Regular albertc30's Avatar
    Join Date
    May 2012
    Location
    Norfolk
    Posts
    969
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: The password supplied is not correct... It is!

    Hi all.

    The issue was in the invoice sheet protected with the correct password but unlike the password stated in the code, it was actually saved in CAPS LOCK!!! Ops...

    It's working now and with your new code as per advice.

    Much appreciated guys.

    I'll have to look into the breakpoint thing.

    Never used it but I think I got it. Please see pic.

    I think that cant use code in protected sheet guided me in the right direction?!

    https://www.dropbox.com/s/e9kpwsv8u6...ot_42.png?dl=0

    Last edited by albertc30; Jul 31st, 2019 at 02:49 PM.
    Many thanks for all the help, much appreciated.

    Regards,
    Albert

    Reminder
    Remember to use code tags people.

  8. #8
    Board Regular
    Join Date
    Apr 2010
    Posts
    167
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Re: The password supplied is not correct... It is!

    Quote Originally Posted by albertc30 View Post
    Hi all.

    The issue was in the invoice sheet protected with the correct password but unlike the password stated in the code, it was actually saved in CAPS LOCK!!! Ops...

    It's working now and with your new code as per advice.

    Much appreciated guys.

    I'll have to look into the breakpoint thing.

    Never used it but I think I got it. Please see pic.

    I think that cant use code in protected sheet guided me in the right direction?!

    https://www.dropbox.com/s/e9kpwsv8u6...ot_42.png?dl=0


    That is your "Locals" window. Go into your 'View' options at the top and enable the "Immediate" window. It is an INVALUABLE tool while coding and debugging.

    Or try hitting Ctrl + G
    Last edited by Steve_; Jul 31st, 2019 at 03:28 PM.

  9. #9
    Board Regular Kenneth Hobson's Avatar
    Join Date
    Feb 2007
    Location
    Tecumseh, OK
    Posts
    3,079
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default Re: The password supplied is not correct... It is!

    I would recommend deleting that link or changing your production version password.

    The local window is good for debugging too. I normally just use a MsgBox() or Debug.Print for simple debugging aids. The Immediate Window can be used interactively as explained. You can execute several lines in Immediate window by separating the lines with colons. e.g.
    Code:
    a="Ken": Msgbox "Hi " & a & "!"

  10. #10
    Board Regular albertc30's Avatar
    Join Date
    May 2012
    Location
    Norfolk
    Posts
    969
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: The password supplied is not correct... It is!

    Quote Originally Posted by Kenneth Hobson View Post
    I would recommend deleting that link or changing your production version password.

    The local window is good for debugging too. I normally just use a MsgBox() or Debug.Print for simple debugging aids. The Immediate Window can be used interactively as explained. You can execute several lines in Immediate window by separating the lines with colons. e.g.
    Code:
    a="Ken": Msgbox "Hi " & a & "!"

    Thanks to all the help everyone.

    The password as it stands its just generic and it will be changed.

    Much appreciated to all of you and for the valuable time you give to the excel community.

    Cheers.
    Many thanks for all the help, much appreciated.

    Regards,
    Albert

    Reminder
    Remember to use code tags people.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •