sorry to bother you all. I'm programming a website and i'm trying to hash the password before storing it in the database but I get the error. I've seen related answers which advice people to use ".ToString()", however when I try this it seems to create more errors. Any help would be greatly appreciated.
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
...should be:
TextBox4.Text.Trim()
The whole line should look like this:
string hashresult = FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox4.Text.Trim(), "SHA1");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.