PDA

View Full Version : Solved: Password sensitivity



MNJ
12-18-2006, 06:56 PM
hi all,

I want my password to be case sensitive. Currently, I'm using UCASE which converts all the letters to uppercase to suit my password.

The macro I'm working on..



'Note use of UCASE()
strUser = UCase(Me.TextBox1.Value)
strPword = UCase(Me.TextBox2.Value)


Select Case strUser
'Note letters
Case "USER"
'Note letters
If strPword = "USER" Then







how do i make my password case sensitive?

CBrine
12-18-2006, 08:19 PM
You should be able to do just this

'Note use of UCASE()
strUser = UCase(Me.TextBox1.Value)
strPword = Me.TextBox2.text


Select Case strUser
'Note letters
Case "USER"
'Note letters
If strPword = "USER" Then



HTH
Cal

MNJ
12-18-2006, 08:25 PM
Thanks. It worked! :friends: but one more thing. I included the msg for incorrect password reading. but it told me syntax error.


MsgBox ("Incorrect password or user name", vbCritical + vbOKOnly, "Error!")



why is this so? Pls suggest

CBrine
12-18-2006, 09:07 PM
Something along these lines?


'Note use of UCASE()
strUser = UCase(Me.TextBox1.Value)
strPword = Me.TextBox2.text


Select Case strUser
'Note letters
Case "USER"
'Note letters
If strPword = "USER" Then
'Your Functions
Else
msgbox "Wrong password entered-Remember it's case sensitive!"
End If
Case Else
Msgbox "Invalid User"
End Select

MNJ
12-19-2006, 06:49 PM
To be more precise,this is my whole code:




Private Sub CommandButton1_Click()

Dim w As Worksheet, c As Range, r As Range
Dim strUser As String, strPword As String, strWs As String
Sheets("Main").Select

'Note use of UCASE()
strUser = UCase(Me.TextBox1.Value)
strPword = Me.TextBox2.Text


Select Case strUser
'Note letters
Case "USER"
'Note letters
If strPword = "USER" Then
'Only show sheets in this list
Sheets("Records").Visible = False
Sheets("AC").Visible = False
Sheets("HI").Visible = False
Sheets("YAcht").Visible = False

Sheets("Intro").Visible = xlSheetVisible
Sheets("Calculations").Visible = xlSheetVisible
'Hide columns for 'USER'
Sheets("Calculations").Range("L1:P1").Columns.Hidden = True

'Disable Format/Columns/Unhide menu item for 'USER'
With Application.CommandBars("Format").Controls("Column").Controls("Unhide")
.Enabled = False
.Visible = False
End With

Unload Me
End If
'Note capital letters
Case "ADMIN"
'Note capital letters
If strPword = "ADMIN" Then
'View all sheets
For Each Sh In Sheets
Sh.Visible = xlSheetVisible
Next Sh

'Show columns for 'ADMIN'
Sheets("ELEMENT").Range("L1:P1").Columns.Hidden = False

Unload Me
End If
Case Else
MsgBox "Incorrect passwword or user name", vbCritical + vbOKOnly, "Error!"
End Select

End Sub





I tried inputting your code into mine. But I can't seem to get the " Error" msg box when the password is wrong.

Could you tell me where my mistake it. Btw, I got this code from another forum.

CBrine
12-20-2006, 07:23 AM
This should take care of it.

Private Sub CommandButton1_Click()

Dim w As Worksheet, c As Range, r As Range
Dim strUser As String, strPword As String, strWs As String
Sheets("Main").Select

'Note use of UCASE()
strUser = UCase(Me.TextBox1.Value)
strPword = Me.TextBox2.Text


Select Case strUser
'Note letters
Case "USER"
'Note letters
If strPword = "USER" Then
'Only show sheets in this list
Sheets("Records").Visible = False
Sheets("AC").Visible = False
Sheets("HI").Visible = False
Sheets("YAcht").Visible = False

Sheets("Intro").Visible = xlSheetVisible
Sheets("Calculations").Visible = xlSheetVisible
'Hide columns for 'USER'
Sheets("Calculations").Range("L1:P1").Columns.Hidden = True

'Disable Format/Columns/Unhide menu item for 'USER'
With Application.CommandBars("Format").Controls("Column").Controls("Unhide")
.Enabled = False
.Visible = False
Else
Msgbox "Incorrect password"
end
End With

Unload Me
End If
'Note capital letters
Case "ADMIN"
'Note capital letters
If strPword = "ADMIN" Then
'View all sheets
For Each Sh In Sheets
Sh.Visible = xlSheetVisible
Next Sh

'Show columns for 'ADMIN'
Sheets("ELEMENT").Range("L1:P1").Columns.Hidden = False

Unload Me
ELSE
Msgbox "The password is incorrect"
end
End If
Case Else
MsgBox "Incorrect passwword or user name", vbCritical + vbOKOnly, "Error!"
End Select

End Sub

MNJ
12-20-2006, 06:38 PM
Dear CBRINE,
many thanks for your follow up. It seems that there's a compile error missing : Else without if. So being a newbie as I am, I added IF to become Else If. But then it's a syntax error.

Pls guide me on how to overcome this problem.

Thanks. :)

CBrine
12-20-2006, 07:16 PM
MNJ,
My bad, I put the else in the wrong place. This should fix you up.


Dim w As Worksheet, c As Range, r As Range
Dim strUser As String, strPword As String, strWs As String
Sheets("Main").Select

'Note use of UCASE()
strUser = UCase(Me.TextBox1.Value)
strPword = Me.TextBox2.Text


Select Case strUser
'Note letters
Case "USER"
'Note letters
If strPword = "USER" Then
'Only show sheets in this list
Sheets("Records").Visible = False
Sheets("AC").Visible = False
Sheets("HI").Visible = False
Sheets("YAcht").Visible = False

Sheets("Intro").Visible = xlSheetVisible
Sheets("Calculations").Visible = xlSheetVisible
'Hide columns for 'USER'
Sheets("Calculations").Range("L1:P1").Columns.Hidden = True

'Disable Format/Columns/Unhide menu item for 'USER'
With Application.CommandBars("Format").Controls("Column").Controls("Unhide")
.Enabled = False
.Visible = False
End With
Unload Me
Else
MsgBox "Incorrect password"
End
End If
'Note capital letters
Case "ADMIN"
'Note capital letters
If strPword = "ADMIN" Then
'View all sheets
For Each Sh In Sheets
Sh.Visible = xlSheetVisible
Next Sh

'Show columns for 'ADMIN'
Sheets("ELEMENT").Range("L1:P1").Columns.Hidden = False

Unload Me
Else
MsgBox "The password is incorrect"
End
End If
Case Else
MsgBox "Incorrect passwword or user name", vbCritical + vbOKOnly, "Error!"
End Select

MNJ
12-22-2006, 12:57 AM
Hi,

Thanks for your reply. I ran your code and it seemed fine. But I just wanted to add one more thing.

if the password is wrong, how do i close the workbook immediately?

I tried this :




Workbooks("BOOK.XLS").Close SaveChanges:=False


and I pasted right after this line



MsgBox "Incorrect passwword or user name", vbCritical + vbOKOnly, "Error!"

but i was wondering why didn't the workbook close!:banghead:

Pls guide me on where do i go from here. I really want to learn! :mkay

CBrine
12-22-2006, 11:33 AM
MNJ,
The code you added is the correct code, but it's kinda in the wrong place. You have added it to the Case Else section. It only executes if the user name is incorrect, if the user name is correct with a wrong password it will never hit that code. I would leave it there to stop an invalid user, but add it just after both the
msgbox "Incorrect Password"
sections of code to close the workbook when an incorrect password is entered.

PS- Just as a cavet, if you are looking to build a secure solution for data, this is not the way to go. I and many others on this board could slice through this like a hot knife through butter. Look outside of excel for a secure solution.

Cal

MNJ
12-28-2006, 07:57 PM
Hey,

sorry for the late reply. facing some communication error here. Thanks for pointing out. I did as u suggested.

Many thanks for your help. :friends:

MNJ.