如何在SHA 256中将哈希密码解码为字符串 [英] How to decode Hash password to string in SHA 256

查看:84
本文介绍了如何在SHA 256中将哈希密码解码为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Net.Mail;
using System.Text;
namespace Ordering_System
{
    public partial class ForgetPassword : System.Web.UI.Page
    {
        string cs = Global.CS;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btn_Submit_Click(object sender, EventArgs e)
        {
            string email = TextBox1.Text;
            string sql = "SELECT Username,Hash,MemEmail FROM Member";
            SqlConnection con = new SqlConnection(cs);
            SqlCommand cmd = new SqlCommand(sql, con);

            con.Open();
            if (con.State == ConnectionState.Open)
            {
                SqlDataReader dtr = cmd.ExecuteReader();

                while (dtr.Read())
                {
                    if (dtr[2].ToString().Equals(TextBox1.Text))
                    {
                        MailMessage mail = new MailMessage();
                        mail.To.Add(dtr[2].ToString());
                        mail.From = new MailAddress("redactedEmail@xxx.yyy");
                        mail.Subject = "Your userId and Password";
                        mail.Body = "<h2>DailyDemand<br />Username and Password Recovery</h2><br />Username :" + dtr[0].ToString() + "<br />" + "Password :" + dtr[1].ToString() + "";
                        mail.IsBodyHtml = true;
                        SmtpClient client = new SmtpClient();
                        client.Port = 587;
                        client.EnableSsl = true;
                        client.Timeout = 10000;
                        client.Host = "smtp.xxx.yyy";
                        client.DeliveryMethod = SmtpDeliveryMethod.Network;
                        client.UseDefaultCredentials = false;
                        client.Credentials = new System.Net.NetworkCredential("redactedEmail@xxx.yyy", "PASSWORD");
                        client.EnableSsl = true;
                        client.Send(mail);
                        Label1.Text = "Your Password already sent to your Email, Please Check ";


                        break;
                    }
                    else
                    {
                        Label1.Text = "Email is not Valid! Please Try Again! <br /> <a href="MemReg.aspx" style="color:Blue">Sign Up</a><br />";
                    }

                }
            }
        }
    }
}




推荐答案

除了Marcin Kozub [ ^ ]解决方案让我解释一些事情



哈希与加密/编码技术完全不同。加密/解密过程是可逆的但是Hashing是不可逆的。生成密码的哈希并在登录过程中进行比较。



参考:

http://support.microsoft.com/kb/307020 [ ^ ]
In addition to Marcin Kozub[^] solution let me explain few things

Hashing is entirely different from encryption/encoding techniques.Encryption/Decryption process are reversible but Hashing is not reversible.Generate a hash for a password and compare it during sign in process.

Refer:
http://support.microsoft.com/kb/307020[^]


你无法解码SHA / MD5。他们只是 One Way Hashing algorythms。你会在这里找到很好的解释:

http:/ /stackoverflow.com/questions/4948322/fundamental-difference-between-hashing-and-encryption-algorithms [ ^ ]



加密/解密你的良好开端在这里找到:

使用C#加密和解密数据 [ ^ ]
You cannot decode SHA/MD5. They are only One Way Hashing algorythms. You will find good explanations here:
http://stackoverflow.com/questions/4948322/fundamental-difference-between-hashing-and-encryption-algorithms[^]

Good start to encrypting/decrytping you will find here:
Encrypt and Decrypt Data with C#[^]


SHA256代码是不可能的,它是根据密码构建的,但不是密码的编码。因此无法从SHA256代码中取回密码。



您也可以尝试从其CRC代码重建消息。 SHA256的原理相同,只是更加复杂,以防止伪造具有给定SHA256代码的消息。
It is impossible, the SHA256 code is built from the password but is not an encoding of the password. So it is not possible to get back the password from the SHA256 code.

You can as well try to rebuild a message from its CRC code. SHA256 is the same principle, just more complicated to prevent forgery of a message that have a given SHA256 code.


这篇关于如何在SHA 256中将哈希密码解码为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆