Hello,

I have a login screen in my VB 6 program, it is for teachers,

I have a user-name text box and password text box. There is also a login button.

I want there to be one password for all teachers but I want each teacher to have their own user-name. I am using an if statment for this but will only allow me use one user-name.

Please help.

Thanks

I can see in my crystal ball that error is in line 7 in 2nd sub right after you declare variables...

:D.. come on, put some code here so we can see where is problem

Private Sub cmdLogin_Click()

If txtUsername.Text = "ADB" Then
'if the username text box is equal to ADB...

If txtPassword.Text = "HSFC" Then
'and if the password text box is equal to HSFC then the user will be logged in

Unload Me
'closes current form

frmLoggingIn.Show
'shows the logging in form

End If
'ends if the if statement

Else
MsgBox "Sorry you have entered either an incorrect Username and/or Password, please try again."
'if anything apart from ADB and HSFC is entered then a message box will be shown saying, 'Sorry you have entered either an incorrect Username and/or Password, please try again.'

Login.Show
'shows the login form

txtUsername.Text = ""
'if the user trys to login again the username text box will reset and will have nothing inside it

txtPassword.Text = ""
'if the user trys to login again the password text box will reset and will have nothing inside it

txtUsername.SetFocus

End If
'ends the if statement

End Sub

hi,
i have a questions for you..

1. are you didn't used database in your project? how do you check user name if all teacher hv their own user name? in your code just teacher with user name 'adb' can log in, another teacher cannot do that.
2. why you should call frmLoggingIn.Show if login success?? its make you circling in form login. you must call another form.
3. why you call Login.Show if login failed, whereas you in login form? you don't have to call login form again. just clear all the textboxes.
4. Please use code tags

Private Sub cmdLogin_Click()
    If txtUsername.Text = "ADB" Then ' how do you check this? just ADB can log in
        If txtPassword.Text = "HSFC" Then ' Password always same for all teacher
            Unload Me
            'frmLoggingIn.Show '--> this should change with another form
        End If
    Else
        MsgBox "Sorry you have entered either an incorrect Username and/or Password, please try again."
        'Login.Show '--> this not have to do, you in log in form now.
        txtUsername.Text = ""
        txtPassword.Text = ""
        txtUsername.SetFocus
    End If
End Sub

hi,
i have a questions for you..

1. are you didn't used database in your project? how do you check user name if all teacher hv their own user name? in your code just teacher with user name 'adb' can log in, another teacher cannot do that.
2. why you should call frmLoggingIn.Show if login success?? its make you circling in form login. you must call another form.
3. why you call Login.Show if login failed, whereas you in login form? you don't have to call login form again. just clear all the textboxes.

This is my code for the usernames

Private Sub cmdLogin_Click()

Select Case UCase(txtUsername.Text)
Case "ADB", "WEG", "TJS", "MAA" '

Unload Me
'closes current form

frmLoggingIn.Show
'shows the logging in form
        
Case Else
MsgBox "Sorry you have entered either an incorrect Username and/or Password, please try again."
'displays a message, saying, ' Sorry you have entered either an incorrect Username and/or Password, please try again'

txtUsername.Text = ""
'if the user trys to login again the username text box will reset and will have nothing inside it

txtPassword.Text = ""
'if the user trys to login again the password text box will reset and will have nothing inside it

txtUsername.SetFocus

End Select

End Sub

how would i incorporate a code where i could only use one password for all teachers.. 'HSFC'

try this :

Private Sub cmdLogin_Click()
    If txtPassword.Text = "HSFC" Then ' Password always same for all teacher
        Select Case UCase(txtUsername.Text)
        Case "ADB", "WEG", "TJS", "MAA"
            Unload Me
            frmLoggingIn.Show
        Case Else
            MsgBox "Incorrect user name"
            txtUsername.Text = ""
            txtPassword.Text = ""
            txtUsername.SetFocus
        End Select
    Else
        MsgBox "Sorry you have entered either an incorrect Username and/or Password, please try again."
        txtUsername.Text = ""
        txtPassword.Text = ""
        txtUsername.SetFocus
    End If
End Sub

Login info must be stored in Database, to enable multiple user with their individual password.

Login info must be stored in Database, to enable multiple user with their individual password.

Or a text file.

Preferably in a database for security reason.

If using text file ensure that you are using some encryption algorithm.

Encryption not so sorely for usernames but for passwords. Usernames can not really give you access to anything, it's the passwords that play the main role.

@Michelle, have you considered starting the use of a database or text file?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.