我正在为学校做一个应用程序,并且在将密码插入到我的用户数据库时需要密码帮助。我是用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