0

我想问你关于 ASP.net C sharp 来解决我的问题。我创建了 MySql 数据库,该数据库在用户注册表中包含这些字段(用户名,电子邮件,密码,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();) 出现错误,即“Exception was unhandled by user code” 提示:程序成功注册了任何没有 slatHash 函数的用户。

4

0 回答 0