7 Replies - 2225 Views - Last Post: 08 March 2013 - 10:43 PM Rate Topic: -----

#1 mercy_angel  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 132
  • Joined: 28-February 13

Username and password form with error help

Posted 04 March 2013 - 03:59 AM

I'm trying to write some form, where user write username and password, and I don't know how to..for example, if user write wrong password, one message box show that password is only wrong..Or if both, both..or username, username. And if user wrong 3 times, anything, message box shows and "tell" Username is:user Password is: password..

Option Explicit

Private Sub cmdExit_Click()
End

End Sub

Private Sub cmdCheck_Click()
Dim Answer As Integer
If txtPass.Text = txtPass.Tag And txtUser.Text = txtUser.Tag Then


MsgBox "OK", vbOKOnly + vbExclamation, "Accepted!"
Else

Answer = MsgBox("Wrong", vbRetryCancel + vbCritical, "Error!")
    If Answer = vbRetry Then
    txtPass.SelStart = 0 
    txtPass.SelLength = Len(txtPass.Text) 
    txt.SelStart = 0
    txtUser.SelLength = Len(txtUser.Text)

    Else
    End
    End If
End If
txtPass.SetFocus
txtUser.SetFocus

End Sub




txt.SelStart = 0 mine mistake..

txtUser.SelStart = 0



Is This A Good Question/Topic? 1
  • +

Replies To: Username and password form with error help

#2 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5675
  • View blog
  • Posts: 12,191
  • Joined: 02-June 10

Re: Username and password form with error help

Posted 04 March 2013 - 08:57 AM

Your assignment is to do this in VB6? You're deliberately using a language that's been dead for a decade? Should this be moved to VB.NET?

Please read: This is not the VB.NET forum
Please read: Is learning VB6 now a complete waste of time?
Was This Post Helpful? 0
  • +
  • -

#3 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Username and password form with error help

Posted 04 March 2013 - 10:04 PM

tlhin's admonishments notwithstanding, I have some advice. First, you need to keep in mind that you are counting the number of times that the user enters your sub, because if he checks cmdCheck three times you are going to change the behavior. This is a good example of when a Static variable is useful. Static variables are only visible inside the Sub, but they hold their value between calls. So:
Option Explicit

Private Sub cmdExit_Click()
Unload Me
End Sub

Private Sub cmdCheck_Click()
Static TimesTried as Integer
Dim Answer As Integer
If txtPass.Text = txtPass.Tag And txtUser.Text = txtUser.Tag Then
    MsgBox "OK", vbOKOnly + vbExclamation, "Accepted!"
ElseIf TimesTried = 2 Then
    'Message Box that tells the user the username and password, although I would just kick him out
Else
    Answer = MsgBox("Wrong", vbOkOnly + vbCritical, "Error!")
    TimesTried = TimesTried + 1
    txtUser.Text = ""
    txtPass.Text = "" 
End If
txtUser.SetFocus
End Sub


So, just empty both text boxes if the user is wrong. Don't let the user retry in the context of clicking the check button, let him hit the check button each time he tries a new userid/password combination. Don't set focus on both the user and password, doesn't make sense. Just set focus on the user because that's where he's going to begin typing again. Oh, and don't use End, just unload the form. It will do whatever housekeeping it is supposed to do and then end on its own.

How's that work for you? :)

This post has been edited by BobRodes: 04 March 2013 - 10:05 PM

Was This Post Helpful? 0
  • +
  • -

#4 mercy_angel  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 132
  • Joined: 28-February 13

Re: Username and password form with error help

Posted 05 March 2013 - 04:07 PM

View PostBobRodes, on 04 March 2013 - 10:04 PM, said:

tlhin's admonishments notwithstanding, I have some advice. First, you need to keep in mind that you are counting the number of times that the user enters your sub, because if he checks cmdCheck three times you are going to change the behavior. This is a good example of when a Static variable is useful. Static variables are only visible inside the Sub, but they hold their value between calls. So:
Option Explicit

Private Sub cmdExit_Click()
Unload Me
End Sub

Private Sub cmdCheck_Click()
Static TimesTried as Integer
Dim Answer As Integer
If txtPass.Text = txtPass.Tag And txtUser.Text = txtUser.Tag Then
    MsgBox "OK", vbOKOnly + vbExclamation, "Accepted!"
ElseIf TimesTried = 2 Then
    'Message Box that tells the user the username and password, although I would just kick him out
Else
    Answer = MsgBox("Wrong", vbOkOnly + vbCritical, "Error!")
    TimesTried = TimesTried + 1
    txtUser.Text = ""
    txtPass.Text = "" 
End If
txtUser.SetFocus
End Sub


So, just empty both text boxes if the user is wrong. Don't let the user retry in the context of clicking the check button, let him hit the check button each time he tries a new userid/password combination. Don't set focus on both the user and password, doesn't make sense. Just set focus on the user because that's where he's going to begin typing again. Oh, and don't use End, just unload the form. It will do whatever housekeeping it is supposed to do and then end on its own.

How's that work for you? :)/>



Code is fine, thanks you, but If user hit wrong username, and hit ok password, why both field set to empty? Doesn't make sense for me. It's ok to empty field only for wrong hitted, not both, isn't ?
Was This Post Helpful? 0
  • +
  • -

#5 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: Username and password form with error help

Posted 06 March 2013 - 01:08 AM

View Postmercy_angel, on 05 March 2013 - 11:07 PM, said:

Code is fine, thanks you, but If user hit wrong username, and hit ok password, why both field set to empty? Doesn't make sense for me. It's ok to empty field only for wrong hitted, not both, isn't ?


Personally, I would agree with Bob's clearing both fields.

If you leave "correct" field populated, you're acknowledging that it's a valid userID or password, so as a failsafe, it's better to clear both fields.

I know it becomes a pain for the user to key both items again, but on the other hand, a bot or unscrupulous person could, over time, build up quite a combination of valid userID and passwords if you leave the fields populated.

Again, that's just my opinion, at the end of the day, it's your code, so the final decision is yours.
Was This Post Helpful? 0
  • +
  • -

#6 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Username and password form with error help

Posted 06 March 2013 - 09:40 PM

Suppose you go on the internet, put in a few wrong userids and passwords, and see how many of them leave the information in. (You could start with this one.)

The point is that if someone is attempting an attack on the site it requires a lot less effort if the previous attempt is still in the box.

This post has been edited by BobRodes: 06 March 2013 - 09:43 PM

Was This Post Helpful? 0
  • +
  • -

#7 mercy_angel  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 132
  • Joined: 28-February 13

Re: Username and password form with error help

Posted 08 March 2013 - 04:39 AM

Thanks guys, I solved that. But now, i want to put some progress bar, and when click Check button, progress bar is do what he do, and then show message, where is password and user ok, or not. I have code for progress bar, but don't know where to put it.

Option Explicit


Private Sub Command1_Click()
End
End Sub

Private Sub Form_Load()
ProgressBar1.Value = ProgressBar1.Min
End Sub


Private Sub Timer1_Timer()
ProgressBar1.Value = ProgressBar1.Value + 10
If ProgressBar1.Value = 50 Then
ProgressBar1.Value = ProgressBar1 + 50
If ProgressBar1.Value >= ProgressBar1.Max Then
Timer1.Enabled = False
End If

End If
End Sub



Was This Post Helpful? 0
  • +
  • -

#8 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Username and password form with error help

Posted 08 March 2013 - 10:43 PM

You lost me pretty much after you said you wanted to make a progressBar.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1