现在的位置: 首页 > 综合 > 正文

将现有系统用户密码转为.text加密方式的密码

2012年11月29日 ⁄ 综合 ⁄ 共 1433字 ⁄ 字号 评论关闭

因为领导要求建立一个博客,于是开始了.text的使用研究过程。

之前已经有一个系统,系统里面有所有用户的个人信息,其中密码是没经过加密的。一开始听说.text是用md5加密的,所以想到将动网论坛的用户导入.text的用户表blog_config中,但经过“千辛万苦”导入后发现,原来动网论坛的用户并不能登陆.text系统。在google上搜索资料发现,原来动网系统是用16位的MD5加密方式,而.text的是用32位的MD5加密的。晕,没办法,唯有想到将没加密的密码转为符合.text加密要求的密码,于是动手做了一个加密密码的小程序。程序主要代码如下:

using System.Security.Cryptography;

using System.Web.Security;

//(记得using这两个名字空间)

public static string Encrypt(string password)   //密码加密程序,.text中也提供有的

  {

   // Force the string to lower case

   //

   password = password.ToLower();

   Byte[] clearBytes = new UnicodeEncoding().GetBytes(password);

   Byte[] hashedBytes = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);

   return BitConverter.ToString(hashedBytes);

  }

private void Button1_Click(object sender, System.EventArgs e)    //更新密码

  {

  

   OleDbConnection myConn = new OleDbConnection(strConn);

   string strSQL1="select * from tablename";  //自己的放用户和密码的表

   OleDbDataAdapter da=new OleDbDataAdapter(strSQL1,myConn);

   OleDbCommandBuilder cmdbd=new OleDbCommandBuilder(da);

   myConn.Open();

   DataTable tb= new DataTable(); 

   da.Fill(tb); 

   myConn.Close();

   foreach(DataRow myRow in tb.Rows)

   {

    //myRow.BeginEdit();

    myRow["password"]=Encrypt(myRow["password"].ToString());

    //Response.Write(myRow["password"].ToString());

   }

   //tb.GetChanges();

             

   myConn.Open();

   

   da.Update(tb);

   //da.Fill(tb);

   myConn.Close();

        

   Button1.Enabled=false;

  }

记住记得为用户表建立主键,否则会出现出错信息,如果出现出错信息,在百度上搜索错误信息就可以找到很多解决的文章。

【上篇】
【下篇】

抱歉!评论已关闭.