非常抱歉打扰到大家。我正在编写一个网站程序,尝试将密码哈希后再存储到数据库中,但是我遇到了错误。我看到一些相关的答案建议使用“.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>");
}```
Trim()
... 那么你的下一个错误是什么? - rfmodulatorConvert.ToInt32()
部分即可。 - rfmodulator