Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I want to add ip detection to prevent multi-accounts.

If the login is not busy, and all the details are correct that you are registered. but if there is a database user with the IP has the same ip you are trying to register a person should see a message box that the account of such ip exists and registration should not happen.

Online there is a column "ip" and when the user registers saves ip it there.

in TextBox1.Text displays the current IP

http://obrazki.elektroda.pl/7486131600_1409311859_thumb.jpg[^]

Public Sub create(ByVal sql As String)

    Try

        con.Open()

        Dim sqlStr As String = "SELECT COUNT(*) FROM `users` WHERE `login` = @uname"
        Dim cmd As New MySqlCommand(sqlStr, con)
        cmd.Parameters.AddWithValue("@uname", txtuser.Text)
        Dim rowCount As Int16 = Convert.ToInt32(cmd.ExecuteScalar())


        If rowCount <> 0 Then
            MsgBox("Sorry, this user already exists!")
            Return
        End If

        If rowCount = 0 Then

        End If
        With cmd
            .Connection = con
            .CommandText = sql
            result = cmd.ExecuteNonQuery

            If result = 0 Then
                MsgBox("Registration failed!")
            Else
                MsgBox("You are now registered.")
                Me.Close()

            End If

        End With
    Catch ex As Exception

    End Try
    con.Close()
End Sub
Posted
Comments
Herman<T>.Instance 29-Aug-14 8:32am    
Do you check internal, external or both IP?
Łuki Gra 29-Aug-14 8:37am    
I use this code

Imports System.Net

TextBox1.Text = (GetIP())
End Sub
Function GetIP() As String
Dim IP As New WebClient
Return IP.DownloadString("http://icanhazip.com/")
End Function

1 solution

It depends on the environment: if this is web based (and that's the only time that IP addresses are relevant) there are two problems:
1) Internet IP addresses are not specific to a single machine: they are specific to the router which connects the PC's to the internet. So if you have a hundred PC's in the same company they will all have the same IP address. Your system will prevent 99 of those from registering, which may not be optimal...
2) Most domestic IP addresses are not static: they change every time the router connects to the internet and the ISP assigns an address from it's "free pool". See here: Using IP based Geolocation - and why it's pretty much useless.[^]

If this is a LAN based IP address, you also can't rely upon it, as most DHCP servers allocate these on a "first come, first served" basis - meaning the IP address is likely to reflect the order in which the PC's were last turned on for the day.

Basically? I'd drop the idea - it's easy to do, but it's going to cause you more grief than it will help!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900