Posted on 2003-02-22
Medium Priority
Last Modified: 2010-05-01
Begginer Question

I am trying to create a login screen where the user has to put a username and password.

I have an sql table with the 4 headers
username (prim key}

Eventually I want to determine what they have access to by who they login as.

I am using visual Basic .NET

Any help would be great
Question by:leafster
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8001272
Well, under the command button on the password screen, I would have some statements as follows.

Private sub Command1_Click()
dim Password as String
dim inI as Integer
dim AcceptedFirstName() as String
dim AcceptedLastName() as String
dim AcceptedProfile as String

if Password = "whatever you want the password to be for a certian type of access" then

For inI = 1 to NumberofNames
 if FirstName = AcceptedFirstName(inI) then
   if LastName = AcceptedLastName(inI) then
      if Profile = AcceptedProfile (inI) then
        exit for
      end if
   end if
 end if
Next inI

end if

End sub

And then repeat this type of loop for each type of access you have.  You will also have to assign values for all accepted users first and last names and profiles for each level of access.  If you need more explanation, let me know.  I should beable to give you an example if you don't quite get it.


Author Comment

ID: 8001327
I guess what I mean is I for starters just want to use the username and password from the sql table and the first name and last name is just for reference so I will know who they were.
As for the profile I want to use it as if member of certain profile then they will be able to see certain things. But for starters wher I am just trying to figure this out the login with username and password is a good place to start.

Examples would be fantastic

Expert Comment

ID: 8001424
ok, give me a few min.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 8001496
Follow these steps exactly.

Open a new application.

Create 2 textboxes, and one command button.
Name them txtUsername and txtPassword and cmdEnter.

Add one more forms to the application.  So you should have Form1,and Form2.

Now, add the following code.

Private Sub Command1_Click()
Dim BoolPassword As Boolean
Dim inI As Integer
Dim AcceptedPassword() As String
Dim AcceptedUsername() As String
Dim inNumUsers As Integer

inNumUsers = 3

ReDim AcceptedPassword(1 To inNumUsers) As String
ReDim AcceptedUsername(1 To inNumUsers) As String

'   this example has 3 users
AcceptedPassword(1) = "Joe"
AcceptedPassword(2) = "Bob"
AcceptedPassword(3) = "Jim"

AcceptedUsername(1) = "Joe"
AcceptedUsername(2) = "Bob"
AcceptedUsername(3) = "Jim"

For inI = 1 To inNumUsers

If txtUsername.Text = AcceptedPassword(inI) Then
    If txtPassword.Text = AcceptedPassword(inI) Then
        Form1.Visible = False
        Form2.Visible = True
        BoolPassword = True
    End If
End If

Next inI

If BoolPassword = False Then
Call MsgBox("User name and password are not correct")
txtUsername.Text = ""
txtPassword.Text = ""

End If

End Sub

Private Sub Form_Load()
    Form2.Visible = False
    txtPassword.PasswordChar = "*"
End Sub

Now, you can change all these properties to fit your needs.  Let me know if this works.


Expert Comment

ID: 8001511
Sorry, change

cmdCommand1_Click ()




Author Comment

ID: 8002779
Do I need to create sqldataadapters or datasets so it can read the table named username as by looking at the example I would need to hardcode all the usernames and passwords. I would like for it to read the table to determine if that username and password exists and if it does then it would open the form.

Expert Comment

ID: 8004068
ok, you can do this.

dim filename as string
dim NumNames as Integer

Filename = name of the file

Open Filename for input as #1

Input #1, NumNames
' this will be the first number that will indicate how many possible users there are.

For inI = 1 to NumNames

Input #1, AcceptedUsername(inI)
Input #1, AcceptedPassword(inI)

Next inI

This is a way to get all the possible user names in to your program from a textfile.  

Author Comment

ID: 8004437
Sorry dont mean to sound stupid but you lost me.....

I have an sql table that I want the login to read and if the name is there it would check for password and then allow the user into the program?

Accepted Solution

Jacamar earned 80 total points
ID: 8005869
Option Explicit

Private fUsersWS as Workspace
Private fUsersDB as Database
Private fUsersRS as Recordset

Private sub cmdEnter_Click()

dim EnteredUser as String
dim EnteredPassword as String

FileName = AppendFileToPath(App.Path, "UsersDB.MDB")

Set fUserDB = fUserWS.OpenDatabase(FileName)

EnteredUser = txtUser.text
EnteredPassword = txtPassword.text

SQL = "SELECT * FROM Users WHERE Password=EnteredPassword"
Set fUsersRS = fUsersDB.OpenRecordset(SQL)

if EnteredUser = fUsersRS then
 Call cmdAccessAccepted_Click
 Call msgBox ("Password and Username are not correct",vbinformation)
end if

end sub

Ok, Try this now.  You will have to change a couple of things (command button names, filename, ect), but I think this is the correct way to do this.  Give it a try.


Expert Comment

ID: 8901253
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
LVL 49

Expert Comment

ID: 8964156
Moderator, my recommended disposition is:

    Accept Jacamar's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question