1,105,242 Community Members

VB.net Log in with MS Access 3 attempts then account will terminated/lock

Member Avatar
Denden17
Light Poster
45 posts since Mar 2012
Reputation Points: -1 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

Any1 here i just need help regarding my System. In Log In Form.
I need to be able to terminate/locked the account in vb.net if the user input wrong username/password in my Log In form like 3 attempts is good. and be able to enabled the account also as an Admin. Need help guyz .. im just a newbie in vb.net so simple instructions/code will be greatly appreciated ^^

Member Avatar
Om Alooi
Newbie Poster
11 posts since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

According to your question you have connect with the Access

first Define a variable

like
" Dim count As Integer" in public

then

go to the dataset on the solution bar and create quires

after that

on the OK button write this code

UsersTableAdapter.FillByUsername(SalesDepartmentDataSet.Users, UsernameTextBox.Text)
If SalesDepartmentDataSet.Users.Rows.Count = 0 Then
MsgBox("Invalid Username")
Exit Sub
End If

UsersTableAdapter.FillByUser(SalesDepartmentDataSet.Users, UsernameTextBox.Text, PasswordTextBox.Text)

If SalesDepartmentDataSet.Users.Rows.Count = 1 Then
If SalesDepartmentDataSet.Users.Item(0).Item(7) Then
MsgBox("You Have been blocked...Contact the adminstratore")
End
End If
if you want to enable or disable things for specific user create this
openFrmMain()

if you don't just enter

FrmMain.show()
then continue the code
Else
count += 1

If count = 3 Then
UsersTableAdapter.UpdateBlocked(UsernameTextBox.Text)
MsgBox("Wrong Password...You are blocked")
End
End If
MsgBox("Wrong Password......Try Again")
End If

if you want to enable or disable things for specific user create this

Sub openFrmMain()
FrmMain.BtnInsert.Enabled = SalesDepartmentDataSet.Users.Item(0).Item(3)
FrmMain.BtnUpdate.Enabled = SalesDepartmentDataSet.Users.Item(0).Item(4)
FrmMain.BtnDelete.Enabled = SalesDepartmentDataSet.Users.Item(0).Item(5)
FrmMain.BtnDisplay.Enabled = SalesDepartmentDataSet.Users.Item(0).Item(6)
If SalesDepartmentDataSet.Users.Item(0).Item(1) = "admin" Then
FrmMain.BtnAdmin.Visible = True
FrmMain.BtnAdmin.Enabled = True
Else
FrmMain.BtnAdmin.Visible = False
End If
FrmMain.Show()
End Sub

Member Avatar
Denden17
Light Poster
45 posts since Mar 2012
Reputation Points: -1 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        If cmbUser.Text = "Admin" Then
            If askAdminUsername() And askAdminPassword() = True Then
                If MsgBox("Successfully Login", vbInformation + vbOKOnly, "Welcome") = vbOKOnly Then

                End If
                frmMenuAdmin.Show()
            End If
            If askAdminUsername() = True And askAdminPassword() = False Then
                AdminAttempts = AdminAttempts - 1
                MsgBox("Login failed " & AdminAttempts & " Tries Left ", vbCritical + vbOKOnly, "Login Failed")
                If AdminAttempts = 0 Then
                    MsgBox("Account has been banned ", vbCritical + vbOKOnly, "Banned")
                End If
            End If
            If askAdminUsername() = False And askAdminPassword() = True Then
                MsgBox("Wrong username", vbCritical + vbOKOnly, "Invalid Username ")
            End If

            If askAdminUsername() = False And askAdminPassword() = False Then
                MsgBox("Wrong Account", vbCritical + vbOKOnly, "Wrong Account! ")
            End If
        End If



    End Sub

My code for btnLogin


For function askAdminUsername() and askAdminPassword()

Code:

Private Function askAdminUsername()

        Dim dt As New DataTable
        Dim ds As New DataSet
        ds.Tables.Add(dt)
        con.Open()
        Dim da As New OleDb.OleDbDataAdapter("Select * from AdminUsernamePassword", con)
        da.Fill(dt)

        For Each DataRow In dt.Rows

            If txtUsername.Text = DataRow.item(0) Then
                con.Close()
                Return True

            End If
        Next

        con.Close()
        Return False

    End Function
Private Function askAdminPassword()

        Dim dt As New DataTable
        Dim ds As New DataSet
        ds.Tables.Add(dt)
        con.Open()
        Dim da As New OleDb.OleDbDataAdapter("Select * from AdminUsernamePassword", con)
        da.Fill(dt)

        For Each DataRow In dt.Rows
            If txtPassword.Text = DataRow.Item(1) Then
                con.Close()
                Return True
            ElseIf txtPassword.Text <> DataRow.Item(1) Then
                con.Close()
                Return False

            End If
        Next

    End Function
End Class
Member Avatar
Denden17
Light Poster
45 posts since Mar 2012
Reputation Points: -1 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

got the log in attempts but when it comes to enable and disable the Account havent go it :(

Member Avatar
adam_k
Veteran Poster
1,056 posts since Jun 2011
Reputation Points: 239 [?]
Q&As Helped to Solve: 212 [?]
Skill Endorsements: 17 [?]
 
0
 

Can you share what you've tried for enabling and disabling the account?

Also, if this is a school assignment it's OK, but if you are really using this then I have to disagree with your logic for validating the username and password. What you are doing is you are retrieving the whole table of users and then check against that.
What's wrong with it:
1) Anybody with an ethereal on the network (or simpler tools) can have all accounts.
2) In an environment with hundrend of users you would be transfering twice ! a huge ammount of data.
3) You are testing the validity of the username separately from the validity of the password. They are meant to be used as a pair (user A with password A). In your case any valid username can match to any valid password or all accounts can be logged in with the same password.

Change the logic you are using to retrieving only a count of records where username = txtUsername.text and password = txtPassword.text (Oh and pass the values as parameters). and verify the number of records (it should be 1 for a valid login and not anything else). This way you are having the server (or access in your case) do the job which is faster, you are not transfering data from the server (again access but it makes no difference), you don't give access to your whole table and it has to be a valid combination of username/password.

Member Avatar
Denden17
Light Poster
45 posts since Mar 2012
Reputation Points: -1 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

Its just a school project.. the reason why i separate the two | Username | Password
because i just want to check the user if they inputted a wrong username or password..

Just got a code for locking an account when 3 attempt password is wrong ?

Member Avatar
M.Waqas Aslam
Practically a Posting Shark
837 posts since Aug 2011
Reputation Points: 67 [?]
Q&As Helped to Solve: 137 [?]
Skill Endorsements: 4 [?]
Featured
 
0
 

please check this thread , hope you will find any idea ,
http://www.daniweb.com/software-development/vbnet/threads/412558/1761197#post1761197


Regards

Member Avatar
Denden17
Light Poster
45 posts since Mar 2012
Reputation Points: -1 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

will try thnx for the reply.

Member Avatar
Denden17
Light Poster
45 posts since Mar 2012
Reputation Points: -1 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

it just banned user it doesnt affect the database ^^

Member Avatar
M.Waqas Aslam
Practically a Posting Shark
837 posts since Aug 2011
Reputation Points: 67 [?]
Q&As Helped to Solve: 137 [?]
Skill Endorsements: 4 [?]
Featured
 
0
 

listen , use same logic as you get from above link , in your user table add a new field called enableStatus set the datatype bit/boolean , now count 3 times wrong input , after 3 times wrong input , update that user and change the enableStatus field false ,
now in your login form where you are validating the username and password you should also validate the enableStatus of that user , if status is false then dont allow user to login even with correct username and password , and now about your question's second part , make a form , place a grid in it . show all usernames and enablestatus in grid and allow admin to change the enable status . hope this will clear your logic , make some efforts . if you got any prob then i will try to provide a sample solution to demonstrate all this .

Best Regards

Member Avatar
Denden17
Light Poster
45 posts since Mar 2012
Reputation Points: -1 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

so what do you mean in user table like adding 1 field in my MS Access ? well in MS Access theres no boolean type or maybe your referring to text..
im just a little mess on it .. im not good in english though. but i got your point.

will try but can u give me some hint ? or like putting code, i really need it maybe just not a spoon feed code but a little hint on something like that.

thnx anyways waqasaslammeo u got the point really appreciate your help. but will u show some extra codes ? :)

Member Avatar
adam_k
Veteran Poster
1,056 posts since Jun 2011
Reputation Points: 239 [?]
Q&As Helped to Solve: 212 [?]
Skill Endorsements: 17 [?]
 
0
 

I think access calls binary Yes/No in field type, but you can use a text field for the same reason and have it accept 1/0 or True/False or Enabled/Disabled.

Member Avatar
Denden17
Light Poster
45 posts since Mar 2012
Reputation Points: -1 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

still no luck ..

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: