很抱歉打扰大家。我正在编程一个网站,并且在将密码存储在数据库中之前尝试对密码进行哈希处理,但出现错误。我已经看到了相关的建议,建议人们使用“ .ToString()”,但是当我尝试这样做时,似乎会产生更多的错误。任何帮助将不胜感激。
try
{
//hashing attempt
string hashresult = Convert.ToInt32(FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox4.Text.Trim, "SHA1")); //the error is on this line (TextBox4.Text.Trim)
//.ToString()
//end
SqlConnection con = new SqlConnection(strcon);
if (con.State == System.Data.ConnectionState.Closed)
{
//if its closed the program will open it
con.Open();
}
//texbox info to SQL
SqlCommand cmd = new SqlCommand("insert into user_master_tbl(name,email,dob,region,postcode,user_id,password) values(@name,@email,@dob,@region,@postcode,@user_id,@password)", con);
//connecting textbox to the information typed in
cmd.Parameters.AddWithValue("@name", TextBox3.Text.Trim());
cmd.Parameters.AddWithValue("@email", TextBox1.Text.Trim());
cmd.Parameters.AddWithValue("@dob", TextBox2.Text.Trim());
cmd.Parameters.AddWithValue("@region", DropDownList1.SelectedItem.Value);
cmd.Parameters.AddWithValue("@postcode", TextBox6.Text.Trim());
cmd.Parameters.AddWithValue("@user_id", TextBox9.Text.Trim());
cmd.Parameters.AddWithValue("@password", hashresult);
//firing connection to database
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>" + "alert('Account created successfully, please proceed to login to your account');" + "</script>");
}```
TextBox4.Text.Trim
...应该是:
TextBox4.Text.Trim()
整行应如下所示:
string hashresult = FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox4.Text.Trim(), "SHA1");