我想知道关于ASP.net C sharp解决我的问题。 我创建了MySql数据库,在用户注册表中有这些字段(userName,Email,password,postCode,slowHash) 然后我创建了(PasswordHash)类,其中包含来自此网站的复制代码(https://crackstation.net/hashing-security.htm#aspsourcecode) 之后,我在(注册页面)
中编写了这段代码 namespace MvcNursery
{
public partial class SignUp : System.Web.UI.Page
{
MySql.Data.MySqlClient.MySqlConnection conn;
MySql.Data.MySqlClient.MySqlCommand cmd;
string queryStr;
protected void BTNSignUp_Click(object sender, EventArgs e)
{
// this function for encryption
registerUserWithLowHash();
Response.Redirect("~/SignUpComplete.aspx");
}
private void registerUserWithLowHash()
{
string connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString();
conn = new MySql.Data.MySqlClient.MySqlConnection(connString);
conn.Open();
queryStr = "";
queryStr = "INSERT INTO webappdemo.userregistration (userName, Email, slowHash, postCode)" +
"VALUES(?userName, ?Email, ?slowHash, ?postCode)";
cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn);
cmd.Parameters.AddWithValue("?userName", UserNameSignUp.Text);
cmd.Parameters.AddWithValue("?Email", EmailSignUp.Text);
cmd.Parameters.AddWithValue("?postCode", PostcodeSignUp.Text);
string saltHashReturned = PasswordHash.CreateHash(PasswordSignUp.Text);
int commIndex = saltHashReturned.IndexOf(":");
string extractedString = saltHashReturned.Substring(0, commIndex);
commIndex = saltHashReturned.IndexOf(":");
extractedString = saltHashReturned.Substring(commIndex + 1);
commIndex = extractedString.IndexOf(":");
string salt = extractedString.Substring(0, commIndex);
commIndex = extractedString.IndexOf(":");
extractedString = extractedString.Substring(commIndex + 1);
string hash = extractedString;
cmd.Parameters.AddWithValue("?slowHash", saltHashReturned);
cmd.ExecuteReader();
conn.Close();
}}}
在运行期间,(cmd.ExecuteReader();)中存在错误,即“用户代码未处理异常” 提示:程序注册了没有slatHash功能的任何用户。