I am trying to write an app that can be used by different users with different access levels.
I have some buttons that I am using a Inputbox to ask for and verify the password. I would like the change them to a password char txtbox

However, I dont know how to make that form and have it go to different forms in the app without creating a login for for each button.

Any help would be great. What I read on forums confused me.

The easiest is to use the login form template that comes with VB. If that's no good to you and really want to creat your own, follow these instructions for a basic login form.

Add a new form to the project. Use a textbox and 2 buttons. In the textbox, set the password character, so that prying eyes can't read the password. Make one button for OK and one for Cancel. In the form's properties asign the Accept button and the Cancel Button to the appropriate buttons. In the constructor for the form add a parameter for the password string and add byref to the front of it. In the Click event handler for the OK button assign the Textbox's text to the password string and close the form.

Now in your calling forms declare a new instance of the login form and pass a string that you've already declared to hold the password. declare a DialogResult variable to hold the return from the login form and assign the variable using the ShowDialog method of the form. Check the result. If it's OK verify the password in the string, if not cancel the login.

I created my own Login Form, It actually only asks for a Command Code. There are 4 different command codes based on the area of the app you are trying to access. I want to use an access database to control validation of the access codes. So they can be changed via the app if needed.

I have tried a number of ways to do this based on Howto's I have found on the net. However I cant get them to work. Any ideas would be great.

Here is the code:

Imports System.Data.SqlClient

Public Class loginCMD

    Private Sub OK_Click(sender As System.Object, e As System.EventArgs) Handles OK.Click

        Dim command As New SqlCommand
        Dim connection As New SqlConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Z:\LCARS\modules\user.mdb;Jet OLEDB:Database Password=*******;")
        Dim datareader As SqlDataReader

        With command
            .CommandType = CommandType.Text
            .CommandText = "select cmd from tblcmd"            
        End With
        If connection.State = ConnectionState.Closed Then
            connection.Open()
        End If
        datareader = command.ExecuteReader
        datareader.Read()
        If datareader.HasRows = False Then
            Return
            MsgBox("Command Code Invalid")
            login.Hide()
            Me.Hide()
            Failure.Show()
        Else
            If commandcode.Equals(datareader("CMD").ToString()) Then
                Return
                login.Hide()
                warp.Show()
            Else
                Return
                MsgBox("Command Code Invalid")
                login.Hide()
                Me.Hide()
                Failure.Show()
            End If
        End If

    End Sub

When you click ok the entire VB lockups up and I have to end task.

The biggest problem I see with your code, is you have code ready to execute after the return statement. This code will never execute.

I have switched to an SQL server instead of Acccess.
However, it does the same thing and hangs when you click OK.
I checked the DEBUG log and it shows:
"An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: An attempt to attach an auto-named database for file C:\Users\DaymanetALS\Documents\Visual Studio 2010\Projects\LCARSv2\LCARSv2\bin\Debug\LCARS.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
The program '[5812] LCARSv2.vshost.exe: Managed (v4.0.30319)' has exited with code 1073807364 (0x40010004)."

The MDF it shows does not and has never existed. I think I hit the wrong button when I was adding the Data Source. However, the datasource has since been deleted from the project yet it still wants it. How can I fix this?

I seem to have found and resolved this issue.
There was a line in my config that I must have just said yes to a prompt that got added.
Signin working fine now, just need to get the update code written.

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.