private void btn_login_Click(object sender, RoutedEventArgs e) { SqlConnection sqlCon = new SqlConnection("Server=xxxxx;Database=x;User Id=xxx;Password=xx;"); try { if (sqlCon.State == System.Data.ConnectionState.Closed) sqlCon.Open(); String query = "SELECT COUNT(1) FROM tblUser WHERE Username=@Username AND Password=@Password"; SqlCommand sqlCmd = new SqlCommand(query, sqlCon); sqlCmd.CommandType = System.Data.CommandType.Text; sqlCmd.Parameters.AddWithValue("@Username", txtUsername.Text); sqlCmd.Parameters.AddWithValue("@Password", txtPassword.Text); int count = Convert.ToInt32(sqlCmd.ExecuteScalar()); if (count == 1) { MessageBox.Show("Success!"); } else { MessageBox.Show("Wrong!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { sqlCon.Close(); } }
private static string GetSHA384(string userID, string password) { // SHA classes are disposable, use using to ensure any managed resources are properly disposed of by the runtime using SHA384 sha = new SHA384CryptoServiceProvider(); // convert the username and password into bytes byte[] preHash = Encoding.ASCII.GetBytes(userID + password); // hash the bytes byte[] hash = sha.ComputeHash(preHash); // convert the raw bytes into a string that we can save to a database return Convert.ToBase64String(hash); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)