无法从"method group"转换为"string"



很抱歉打扰大家。我正在为一个网站编程,在将密码存储到数据库之前,我试图对其进行哈希处理,但我遇到了错误。我看到了一些相关的答案,建议人们使用".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");

最新更新