-1
According to my question, in the Gypsy’s response to hash of mac address network card just use two methods.
But in the form of using them to retrieve the data and do the check I’m having an error:
A field initializer cannot Reference that non-static field, method, or propety
Remembering here that the way to use is:
var chave = GetSHA1HashData(GetMacAddress());
I wonder if someone could help me ?
Here 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
I don’t know what you’re doing, where you’re making this mistake. Provide information that helps you respond.
– Maniero
Done @bigown... And this giving wrong time to use them: var key = Getsha1hashdata(Getmacaddress();. Which in case is string and not var.
– Érik Thiago
You can send the full class code?
– Guilherme Portela
@Guillhermeportela made.
– Érik Thiago