我已將我的密碼散列在我的registration.aspx
頁面,並設法通過它登錄。但是,我有這個viewprofile.aspx
頁面,其中它將顯示包括密碼在內的所有客戶詳細信息在FormView
中。我的問題是如何使解密密碼顯示在密碼列中的FormView
?爲了說明這一點,這是我從我的viewprofile.aspx
頁面走到這一步:我如何顯示解密的密碼在gridview?
private void bindgrid()
{
SqlConnection conn = new SqlConnection(connStr);
dt = new DataTable();
com.Connection = conn;
com.CommandText = "SELECT * FROM UserData WHERE Username ='" + Session["New"] + "'";
sqlda = new SqlDataAdapter(com);
sqlda.Fill(dt);
EmployeeFormView.DataSource = dt;
EmployeeFormView.DataBind();
}
鑑於上面的代碼,它給了我所有的細節完美的罰款,但也得到了散列(加密)密碼。任何想法或竅門,你可以分享我將如何解決這個問題?
這是我的業務層所在的頁面哈希碼是:
public static string CreateSHAHash(string Phrase)
{
SHA512Managed HashTool = new SHA512Managed();
Byte[] PhraseAsByte = System.Text.Encoding.UTF8.GetBytes(string.Concat(Phrase));
Byte[] EncryptedBytes = HashTool.ComputeHash(PhraseAsByte);
HashTool.Clear();
return Convert.ToBase64String(EncryptedBytes);
}
這裏是我的registration
頁面代碼,以及它顯示了密碼的哈希:
protected void btn_Registration_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "insert into UserData(Username,Firstname,Lastname,Email,Password,CustomerType,DeliveryAddress,Zip,ContactNumber)values(@Username,@Firstname,@Lastname,@Email,@Password,@CustomerType,@DeliveryAddress,@Zip,@ContactNumber)";
SqlCommand scm = new SqlCommand(insertQuery, conn);
scm.Parameters.AddWithValue("@Username", txtUser.Text);
scm.Parameters.AddWithValue("@Firstname", txtFN.Text);
scm.Parameters.AddWithValue("@Lastname", txtLN.Text);
scm.Parameters.AddWithValue("@Email", txtEmail.Text);
scm.Parameters.AddWithValue("@Password", BusinessLayer.ShoppingCart.CreateSHAHash(txtPW.Text));
scm.Parameters.AddWithValue("@CustomerType", RadioButtonList1.SelectedItem.ToString());
scm.Parameters.AddWithValue("@DeliveryAddress", txtAddress.Text);
scm.Parameters.AddWithValue("@Zip", txtZip.Text);
scm.Parameters.AddWithValue("@ContactNumber", txtContact.Text);
scm.ExecuteNonQuery();
txtUser.Text = "";
txtFN.Text = "";
txtLN.Text = "";
txtEmail.Text = "";
txtAddress.Text = "";
txtZip.Text = "";
txtContact.Text = "";
label_register_success.Text = ("Registration Successful!");
conn.Close();
}
catch (Exception ex)
{
Response.Write("Error:" + ex.ToString());
}
}
散列只是一種方法。你不能解開一個字符串。 –