无法从“方法组”转换为“字符串”

问题描述 投票:1回答:1

很抱歉打扰大家。我正在编程一个网站,并且在将密码存储在数据库中之前尝试对密码进行哈希处理,但出现错误。我已经看到了相关的建议,建议人们使用“ .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>");
            }```
c# html database web hash
1个回答
1
投票
TextBox4.Text.Trim

...应该是:

TextBox4.Text.Trim()

整行应如下所示:

string hashresult = FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox4.Text.Trim(), "SHA1");
© www.soinside.com 2019 - 2024. All rights reserved.