Hi all.
How Can I makes login form for my vb.net project? I would like to make one that can identify the user according to their roles. Eg. Roles 1-4. Role 1 being the lowest user so this user can't use everything on the app. Role 4 as the highest user/administrator can access everything.

The login form must not have a registration form. Me as the developer must create the users. Or the role4/adminstrator must be able to add users on the app.

Can anyone perhaps point me to a sample project like this or a forum that explains everything to do in detail so that I can make one.


Recommended Answers

All 6 Replies

Nothing special required. Just make the startup form your login form. The login form would have a text control for the username and another for the password. For the password box, set the PasswordChar property to "*" to hide the characters.

To use roles you would have to have a database or an encrypted file that contains the ronle number for each user (which you already said you would be assigning).

What in particular are you having trouble with?

Hi, I'm having trouble with the coding. I know how to do a login form in aspx but not VB. This is why I need a tutorial...

Hi, I have created THREE programs with VB. So I dont think Visual Basic Fundamentals will help me with a tutorial for login forms...

Your first step will probably be to add a Login form to your project. The template is included in VB.net. Just use the Add-New Item option. At this point you have the form elements needed to process the login.

One option to store the data for each user, is to use My.Settings. You probably don't want to have too many users but you can still encrypt the data. You might have to test it to see at what point the number of users creates an unacceptable time lag accessing the data. If you want to allow for more users than that a database is probably your next step.

As for code, searching for posts here with the terms VB.net and Login form wil give you lots of examples to learn from.

I have created THREE programs with VB. So I dont think Visual Basic Fundamentals will help me with a tutorial for login forms...

That's the problem when you provide so little information. I have no way of knowing your level of expertise. As I said before, the only thing that distinguishes a login form from any other form is its name. If you have created programs in VB then you already know how to create a form. So I'll ask again, what exactly are you stuck on?

As a simple demo I created a project with two forms, Main and Login. The main form has code

Public Class frmMain

    Private Sub frmMain_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        Me.Visible = False

        If Not frmLogin.LoginSuccessful Then
            MsgBox("login failed")
            Me.Visible = True
        End If

    End Sub

End Class

The login form has two textboxes and one button. The code is

Public Class frmLogin

    Public LoginSuccessful As Boolean

    Private Sub frmLogin_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        LoginSuccessful = False
    End Sub

    Private Sub btnLogin_Click(sender As System.Object, e As System.EventArgs) Handles btnLogin.Click
        LoginSuccessful = txtUsername.Text = "superuser" And txtPassword.Text = "godmode"
    End Sub

End Class

The main form is invisible until the user successfully logs in. If the login fails then the app closes.

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.