• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:


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
1 Solution
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.

leafsterAuthor Commented:
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
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!

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.

Sorry, change

cmdCommand1_Click ()



leafsterAuthor Commented:
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.
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.  
leafsterAuthor Commented:
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?
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.

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?
Moderator, my recommended disposition is:

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

DanRollins -- EE database cleanup volunteer

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now