我正在爲學校做一個應用程序,並且在將密碼插入到我的用戶數據庫時需要密碼幫助。我是用c#編程語言編程的,我正在使用MS服務器2008 R2用於操縱我的數據庫。我正在考慮做一個HASH加密,如果有人幫助我,我會愛上它。當插入數據庫時哈希加密密碼
這是我將數據插入到數據庫代碼:
using (SqlConnection con = new SqlConnection("Data Source=HRC0;Initial Catalog=users;Integrated Security=True")) //MLHIDE
using (SqlCommand sc = new SqlCommand("if NOT exists (select * from users where UserName = @username) insert into users (userName, password) values(@userName, @password)", con))
{
con.Open();
sc.Parameters.AddWithValue("@username", korisnik.Text);
sc.Parameters.AddWithValue("@password", pass.Text);
int o = sc.ExecuteNonQuery();
if (o == -1)
{
MessageBox.Show(Ulaz.Properties.Resources.Niste_ubačeni_u_bazi_korisničk);
this.Hide();
new Registracija().Show();
}
else
{
MessageBox.Show(Ulaz.Properties.Resources.Ubačeni_ste_u_bazi);
con.Close();
this.Hide();
new Form1().Show();
}
,這裏是我的登錄校驗碼:
SqlConnection con = new SqlConnection("Data Source=HRC0;Initial Catalog=users;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select * from users where userName='" + user.Text + "' and password='" + pass.Text + "'", con); //MLHIDE
con.Open();
SqlDataReader re = cmd.ExecuteReader();
if (re.Read())
{
ImeUsera = user.Text;
new UserMode().Show();
this.Hide();
}
else
{
this.Hide();
new LoginFail().Show();
}
}
我使用了一些多語言插件,所以他轉變我的琴絃成''Ulaz.Properties.Resources。''和類似。
散列和加密不是同一件事 – emd
散列(在您的上下文中) - >單向 http://en.wikipedia.org/wiki/ Cryptographic_hash_function 加密 - >雙向(對稱或公鑰) http://en.wikipedia.org/wiki/Encryption – Zerkz
好的,對於我錯誤地使用術語感到抱歉。 – user2445530