According to this my question , in the Cigano's response to the hash of the mac address of the network card, just use two methods.
But how to use them to retrieve the data and do the verification I'm having an error:
A field initializer can not reference that non-static field, method, or propety
Here's how to use it:
var chave = GetSHA1HashData(GetMacAddress());
Can anyone help me?
Here are the methods in question to facilitate:
public class AutenticacaoController : Controller
{
private EntidadesContexto db;
string chave = GetSHA1HashData(GetMacAddress());
public AutenticacaoController()
{
db = new EntidadesContexto();
}
protected override void Dispose(bool disposing)
{
if (db != null) db.Dispose();
base.Dispose(disposing);
}
// GET: Autenticacao
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(String Login, String Senha)
{
//verificando login pelo usuario do banco de dados ...
Usuario login = db.Usuarios.Where(x => x.Login == Login && x.Senha == Senha).FirstOrDefault();
if (login != null)
{
FormsAuthentication.SetAuthCookie(login.Nome.ToString(), false);
Session.Add(".PermissionCookie", login.Perfil);
Session.Add("UsuarioID", login.UsuarioID);
return RedirectToAction("Index", "Home"); //pagina padrao para todos os usuarios...
}
return RedirectToAction("Index");
}
public ActionResult Sair()
{
FormsAuthentication.SignOut();
Session.Remove(".PermissionCookie");
return RedirectToAction("Index");
}
//Aqui são métodos para pegar o endereço MAC da placa de rede do computador e a considerá-la como chave de licença
private string GetSHA1HashData(string data)
{
SHA1 sha1 = SHA1.Create();
byte[] hashData = sha1.ComputeHash(Encoding.Default.GetBytes(data));
StringBuilder returnValue = new StringBuilder();
for (int i = 0; i < hashData.Length; i++)
{
returnValue.Append(hashData[i].ToString());
}
return returnValue.ToString();
}
private string GetMacAddress()
{
string macAddresses = string.Empty;
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
if (nic.OperationalStatus == OperationalStatus.Up)
{
macAddresses += nic.GetPhysicalAddress().ToString();
break;
}
}
return macAddresses;
}
//Aqui termina