Results 1 to 6 of 6

Thread: Trouble with simple password check

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    35

    Question

    Hello, I am having some trouble getting my little cheap password screen to work like I want...Heres what Im trying to get: if the UserName is blank at any time..you get a popup saying theres no username...but if the password is right AND user name has text in it the program opens...heres my code:
    Private Sub cmdOK_Click()
    If txtUserName = "" Then
    MsgBox " Enter A Valid User Name!"
    LoginSucceeded = False
    txtUserName.SetFocus
    End If
    If txtPassword = "password" Then
    LoginSucceeded = True
    Me.Hide
    Else
    MsgBox "Invalid Password, try again!", , "Login"
    txtPassword.SetFocus
    SendKeys "{Home}+{End}"
    End If
    If LoginSucceeded = True Then
    Form1.Visible = True
    Form1.Label1.Caption = "User: " & frmLogin.txtUserName & "..Active"
    End If

    So far all it does on the username popup message but if the password is right it opens anyway...sorry if this is confusing im still new...thanks

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    The problem is that once you have checked to see if there is no user name you shouldn't then check to see if there is a password.

    So try it like this :

    Code:
    Private Sub cmdOK_Click() 
      If txtUserName = "" Then 
        MsgBox " Enter A Valid User Name!" 
        LoginSucceeded = False 
        txtUserName.SetFocus 
      Else
        If txtPassword = "password" Then 
          LoginSucceeded = True 
          Me.Hide 
        Else 
          MsgBox "Invalid Password, try again!", , "Login" 
          txtPassword.SetFocus 
          SendKeys "{Home}+{End}" 
        End If 
      End If
    
      If LoginSucceeded = True Then 
        Form1.Visible = True 
        Form1.Label1.Caption = "User: " & frmLogin.txtUserName & "..Active" 
      End If

  3. #3
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305
    your problem lies with
    Code:
    If txtPassword = PassWord Then
    That's the only condition you have. What you need is,
    Code:
    "If txtPassWord = PassWord AND txtUserName = "User" Then"
    or some other such additional test to make sure that the txtUserName has been entered.

    bob

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    35
    Ok cool thankz to both of you!

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    35

    Question

    By the way how come my code looks normal and not ina section like those? (call me dumb ) hahaha thanks again

  6. #6
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    Have a look at this page :

    http://forums.vb-world.net/index.php?action=bbcode

    It describes everything you need to know

Posting Permissions

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



Click Here to Expand Forum to Full Width