Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string user = tbnome.Text;
- string pass = tbpass.Text;
- System.Security.Cryptography.SHA256Managed crypt = new System.Security.Cryptography.SHA256Managed();
- System.Text.StringBuilder hash = new System.Text.StringBuilder();
- byte[] password = crypt.ComputeHash(Encoding.UTF8.GetBytes(pass), 0, Encoding.UTF8.GetByteCount(pass));
- if (tbpass.Text.Count()>0 && tbnome.Text.Count()>0)
- {
- MessageBox.Show("Well Done");
- /*
- private const int SALTSIZE = 8;
- private bool VerifyLogin(string username, string password)
- {
- SqlConnection conn = null;
- try
- {
- // Configurar ligação à Base de Dados
- conn = new SqlConnection();
- conn.ConnectionString = String.Format(@"DataSource=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\ASUS\Desktop\UNI\Segurança\FichaPratica8_Base\FichaPratica8_Base\Database1.mdf;IntegratedSecurity=True");
- // Abrir ligação à Base de Dados
- conn.Open();
- // Declaração do comando SQL
- String sql = "SELECT * FROM Users WHERE Username = @username";
- SqlCommand cmd = new SqlCommand();
- cmd.CommandText = sql;
- // Declaração dos parâmetros do comando SQL
- SqlParameter param = new SqlParameter("@username", username);
- // Introduzir valor ao parâmentro registado no comando SQL
- cmd.Parameters.Add(param);
- // Associar ligação à Base de Dados ao comando a ser executado
- cmd.Connection = conn;
- // Executar comando SQL
- SqlDataReader reader = cmd.ExecuteReader();
- if (!reader.HasRows)
- {
- throw new Exception("Error while trying to access an user");
- }
- // Ler resultado da pesquisa
- reader.Read();
- // Obter Hash (password + salt)
- byte[] saltedPasswordHashStored = (byte[])reader["SaltedPasswordHash"];
- // Obter salt
- byte[] saltStored = (byte[])reader["Salt"];
- conn.Close();
- byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
- byte[] hash = GenerateSaltedHash(passwordBytes, saltStored);
- return saltedPasswordHashStored.SequenceEqual(hash);
- }
- catch (Exception e)
- {
- MessageBox.Show("An error occurred");
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement