更改/忘记密码可能带有哈希密码?

时间:2016-05-18 09:51:30

标签: asp.net hash forgot-password change-password

我已经实现了我的用户密码进行哈希处理。我想要的是实现忘记/更改密码。但是,我无法将散列密码转换为原始密码,这使我无法执行忘记/更改密码功能。这是我的注册页面中的代码:

cmd.Parameters.AddWithValue("@Password", BusinessLayer.ShoppingCart.CreateSHAHash (txtPW.Text));

这是我的creathash代码:

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);
    }

和我的changepassword页面:

protected void btn_update_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(conn);
        con.Open();
        str = "select * from UserData ";
        com = new SqlCommand(str, con);
        SqlDataReader reader = com.ExecuteReader();
        while (reader.Read())
        {
            if (txt_cpassword.Text == reader["Password"].ToString())
            {
                up = 1;
            }
        }
        reader.Close();
        con.Close();
        if (up == 1)
        {
            con.Open();
            str = "update UserData set Password=@Password where UserName='" + Session["New"].ToString() + "'";
            com = new SqlCommand(str, con);
            com.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar, 500));
            com.Parameters["@Password"].Value = (txt_npassword.Text);
            com.ExecuteNonQuery();
            con.Close();
            lbl_msg.Text = "Password changed Successfully";
        }
        else
        {
            lbl_msg.Text = "Please enter correct Current password";
        }
    }

我想要做的是能够将我的哈希密码转换为原始密码以便更改它。任何招数?或者它可能吗?

0 个答案:

没有答案