如何解密密码? [英] How to decrypt password ?

查看:92
本文介绍了如何解密密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我开发了一个登录页面和注册页面,而忘记了密码页面.我已选择忘记密码".如果我单击忘记密码"链接按钮,并且该电子邮件ID已经存在,那么我会给选项输入电子邮件ID",然后仅向该电子邮件ID发送密码.我正在发送详细信息用户名和密码".密码正在发送至类似"System.Byte []"的邮件.当我发送详细信息时,我需要解密密码.该怎么做?
指导我解决问题.


Hi All,

I have developed one log in page and registration page, and forget password page. I have given option to "forget password". If i click forget password link button i have given option "Enter Email ID" if that email id is already existing then only password send''s to that email id. I am sending details "User name and Password". Password is sending to mail like "System.Byte[]". While i am sending details i need to decrypt the password. How to do that?
Guide me to resolve the issue.


using System;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Net.Mail;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Chirravuri;
 
namespace HIMS.web
{
  public partial class ForgotPassword : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
 
    protected void btnPass_Click(object sender, EventArgs e)
    {
       
//Create Connection String And SQL Statement     
      string ConnectionString = ConfigurationManager.AppSettings["HIMSRMConnectionString"].ToString();
      string strSelect = "SELECT UserName,Password FROM Users WHERE Email = @Email";
      //string strSelect =(@"select Password , convert(varchar(50), DECRYPTBYPASSPHRASE (''12'',password )) AS PWD from Users where UserName=@UserName and Password=@Password", ConnectionString);
              
    SqlConnection connection = new SqlConnection(ConnectionString);
    SqlCommand command = new SqlCommand();
    command.Connection = connection;
    command.CommandType = CommandType.Text;
    command.CommandText = strSelect;
 
    SqlParameter email = new SqlParameter("@Email", SqlDbType.VarChar, 50);
    email.Value = txtEmail.Text.Trim().ToString();
    command.Parameters.Add(email);
        
    //Create Dataset to store results and DataAdapter to fill Dataset 
    DataSet dsPwd = new DataSet();
    SqlDataAdapter dAdapter = new SqlDataAdapter(command);
    connection.Open();
    dAdapter.Fill(dsPwd);
    connection.Close();
    if(dsPwd.Tables[0].Rows.Count > 0 )
    {
      MailMessage loginInfo = new MailMessage();
      loginInfo.To.Add(txtEmail.Text.ToString());
      loginInfo.From = new MailAddress("YourID@gmail.com");
      loginInfo.Subject = "Forgot Password Information";
      loginInfo.Body = "Username: " + dsPwd.Tables[0].Rows[0]["UserName"] + "<br /><br />Password: " + dsPwd.Tables[0].Rows[0]["Password"] + "<br /><br />";
      loginInfo.IsBodyHtml = true;
      SmtpClient smtp = new SmtpClient();
      smtp.Host = "smtp.gmail.com"; 
      smtp.Port = 587;
      smtp.EnableSsl = true;
      smtp.Credentials = new System.Net.NetworkCredential("Email@id", "Password");
      smtp.Send(loginInfo);       
      lblMessage.Text = "Password is sent to you Email ID,you can Login Now <a href=''Login.aspx''>Login</a>";
        
    }
    else
    {
      lblMessage.Text = "Email Address Not Registered";
    }
     
  }
      
  }
 }



我需要解密该密码并将其发送到特定的电子邮件ID.



I need to decrypt and send that password to particular email id.

推荐答案

通常,如果密码是加密的,并且当我们单击忘记密码"时,我们总是会生成一个新密码并在表格中进行更新,并通过相应的电子邮件ID发送电子邮件.

第二个选项,使用反向工程获取密码.即您将与您一起加密算法.只是扭转它.它将解密密码.
仅当未使用不可逆算法(例如MD5算法)对密码进行加密时,此方法才有效.
Normally, if the password is encrypted and when we click on forgot password we always generate a new password and update in the table and send a email on the respective email ID.

2nd option, use reverse engineering to get the password. i.e you will be having encrypt algo with you. Just reverse it. It will decrypt the password.
This will work only if the password is not encrypted with the non-reversible algo (like MD5 Algo).


不要那样做...

如果他们忘记了密码,只需将其重置为随机的字母数字字符串,然后将那个发送给他们...我假设您有一个允许他们更改密码的页面
don''t do it that way ...

If they have forgotten their password, simply reset it to random alpha-numeric string, and send that to them ... I assume you have a page that allows them to change their password


当您从数据库获取密码时,正如您所说的,密码是System.Byte[]数组.将该值存储到变量中,然后转换为字符串.

When you get the password from database, as you said it comes as System.Byte[] array. Store that value into a variable then convert into string.

System.Byte[] array = (System.Byte)dsPwd.Tables[0].Rows[0]["Password"];
string password = ASCIIEncoding.ASCII.GetString(array);
// Your Further code..


这篇关于如何解密密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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