-
I am trying to enter a password. When you enter the first letter of the password wrong a label tells you Incorrect Password. It also works if you enter the first letter right and the second letter wrong. But if I enter the first two letters right and the third letter wrong it doesn't work. This is the code I used:
PrgmPassword = Text1
If Text1 = "Paula" Then
SetStringValue "HKEY_LOCAL_MACHINE", "String Value", PrgmPassword
Unload Me
Form2.Show
End If
If Text1 <> "Paula" Then
Label30 = clr
Label1.Caption = "Incorrect Password - Try Again"
End If
If Text1 = "" Then
Label1.Caption = clr
Label30 = "Please Insert Password"
End If
If Text1 < "Paula" Then
Label30 = "Please Insert Password"
Label1.Caption = clr
End If
Can anyone help me on this?
-
Whats the point in that cos if it tells u after each letter if its right or wrong then people will find it easy to crack the password.
-
He's right, this is a very insecure method of checking a password - are you just doing this as an exercise or are you planning on using it?
What does this line mean? :
If Text1 < "Paula" Then
I would use something like this:
Code:
If Left("Paula", Len(Text1.Text)) <> Text1.Text Then
'string entered is not the start of the string "Paula"
-
You can execute a test every time a letter is pressed by using the KeyPress Event
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Left("Paula", Len(Text1.Text)) <> Text1.Text Then
End Sub
-
if you want to do this, the best way is string paring
Text1_Change
Dim PW as string
Dim x as ling, y as long
PW = Password' whatever that may be
if Right$(PW, 1) = Right$(Text1.Text) Then
'Code for correct Paswword here
else
'Code for incorrect password here
end if
end sub