8 Replies - 3352 Views - Last Post: 29 June 2010 - 08:44 AM Rate Topic: -----

#1 vennesschan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 20-April 10

how to avoid multiple login from different location

Posted 27 June 2010 - 01:06 AM

Hi,

Any idea how can i avoid multiple log into the application at the same time from different locations? If one user is logged in and the other user uses the same ID and PW to log in then he/she will not able to log in.

Any pointers here would be great!

Thanks.
Is This A Good Question/Topic? 0
  • +

Replies To: how to avoid multiple login from different location

#2 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Re: how to avoid multiple login from different location

Posted 27 June 2010 - 02:14 AM

You say 'log in to an application'. Does this mean a website, an application you have built, or something else? Please be more spesific.
Was This Post Helpful? 0
  • +
  • -

#3 vennesschan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 20-April 10

Re: how to avoid multiple login from different location

Posted 27 June 2010 - 03:18 AM

A windows form which is connected to the db.
Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: how to avoid multiple login from different location

Posted 27 June 2010 - 05:33 AM

You could create a table in your db that is always updated when a user logs in or out and check against that when a user tries to log in. Keep in mind that you will also need an option for the admin or user to release their name from the list in the case of a power outage or machine mal-function where the program didn't get to shut down properly. Otherwise, their name will be in the list of logged in users and they will be denied access until that name is manually removed from the list of logged in users.
Was This Post Helpful? 1
  • +
  • -

#5 vennesschan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 20-April 10

Re: how to avoid multiple login from different location

Posted 28 June 2010 - 08:23 PM

Hi,

I am trying to work on the below code for avoiding multiple user log in with the same username and password. However, I am having a trouble to connect the below codes together.

My process below is first check the username and password does it exist in the db, then check if the user is logged in using the same username and password. If the username hasn't log in yet, then update the db with the username and password.

Any pointers here would be great!

Thanks!

'***** Check Username and Password *****
Dim SelectCmd As String
SelectCmd = "SELECT UserId, UserPw FROM UserLogin Where UserId='" & UsernameTextBox.Text & "' and UserPw='" & PasswordTextBox.Text & "'"
Dim Cmd As SqlCommand = New SqlCommand(SelectCmd, conn)

Dim reader As SqlDataReader
reader = Cmd.ExecuteReader()

If reader.HasRows = 0 Then
MessageBox.Show("Invalid Login Details", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

reader.Close()

'***** Check Multiple Log in *****
Dim SelectDoubleCmd As String
SelectDoubleCmd = "SELECT UserId, UserPw FROM Double_Login Where UserId='" & UsernameTextBox.Text & "' and UserPw='" & PasswordTextBox.Text & "'"
Dim SelDouCmd As SqlCommand = New SqlCommand(SelectDoubleCmd, conn)

Dim DoubleLoginreader As SqlDataReader
DoubleLoginreader = SelDouCmd.ExecuteReader()


If DoubleLoginreader.HasRows = -1 Then
MessageBox.Show("User Has Logged In", "Plaese Call Admin Center", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

DoubleLoginreader.Close()

Me.Close() 'If I close the form here, the app is still running till End Sub, and update the db with blank space.

'***** If user hasn't log in, update the db *****
Dim InsertCmd As String
InsertCmd = "Insert into Double_Login (UserId, UserPw) values ('" & UsernameTextBox.Text.Trim() & "','" & PasswordTextBox.Text.Trim() & "')"
Dim InCmd As SqlCommand = New SqlCommand(InsertCmd, conn)
InCmd.ExecuteNonQuery()

'***** Show form finally *****
Dim frm = New MDIParent1
frm.Show()
Me.Visible = False


Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: how to avoid multiple login from different location

Posted 29 June 2010 - 05:05 AM

You can use Exit Sub to stop the execution of the sub at that point. so basically
If DoubleLoginreader.HasRows = -1 Then
doubleloginreader.close()
MessageBox.Show("User Has Logged In", "Plaese Call Admin Center", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Close
Exit Sub
End If
 
DoubleLoginreader.Close()
 
Me.Close() 


Also, Does your program allow multiple users with the same UserID? if not, I wouldn't store the password in the DoubleLogin table, just the logged in UserID and check against that.

This post has been edited by CharlieMay: 29 June 2010 - 05:09 AM

Was This Post Helpful? 1
  • +
  • -

#7 vennesschan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 20-April 10

Re: how to avoid multiple login from different location

Posted 29 June 2010 - 08:09 AM

Hi,

When I work on the user log out process and delete username from the Double_Login db. If user exit the application from btn click, the code works fine and delete username from the db. However, there is a porblem will occur when user directly close the application from the title bar (The X Btn on the upper right corner), then below code will not get exeuted.

Any ideas how to solve the issue?

Thank you so much.

Dim DeleteCmd As String
            DeleteCmd = "Delete from Double_Login where UserId ='" & Me.Text.Trim() & "'"
            Dim Cmd As SqlCommand = New SqlCommand(DeleteCmd, conn)
            Cmd.ExecuteNonQuery()
            Me.Close()
            Exit Sub


Was This Post Helpful? 0
  • +
  • -

#8 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: how to avoid multiple login from different location

Posted 29 June 2010 - 08:12 AM

Take a look at doing this either in the form's Closing Event or the FormClosing Event
Was This Post Helpful? 2
  • +
  • -

#9 vennesschan  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 20-April 10

Re: how to avoid multiple login from different location

Posted 29 June 2010 - 08:44 AM

Thank you!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1