As I develop my WebApp using C# .net, I am looking to implement a feature that allows users to connect from only one specific computer. After the user logs in for the first time, I plan to save their PC details and restrict access if they attempt to log in from a different PC.
My attempted solutions:
1) Saving the IP address upon initial login and verifying it with each subsequent login - however, the issue arises when the IP address changes.
protected string GetIPAddress()
{
System.Web.HttpContext context = System.Web.HttpContext.Current;
string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ipAddress))
{
string[] addresses = ipAddress.Split(',');
if (addresses.Length != 0)
{
return addresses[0];
}
}
return context.Request.ServerVariables["REMOTE_ADDR"];
}
2) Storing a unique key in local storage for verification during login - yet, this method is not foolproof as users can clear local storage, opt out of using it, or have unsupported browsers.
localStorage.setItem("key", "123123");
I seek a more effective and secure approach to achieve this. Any suggestions?