MD5簡單的應用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyMobile;
using System.Security.Cryptography;

public partial class Register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
      
            string username = txtusername.Text;
            string password = MyMobile.BLL.T_users.GetMD5(txtpassword.Text);
            string email = txtmail.Text;

            MyMobile.MODEL.T_users user = new MyMobile.MODEL.T_users();
            user.userid = Guid.NewGuid();
            user.username = username;
            user.password = password;
            user.email = email;

            MyMobile.BLL.T_users buser = new MyMobile.BLL.T_users();
            if (buser.Add(user) == true)
            {
                Response.Write("插入成功");
            }
            else
            {
                Response.Write("插入失敗");
            }
              

 

        }
   //計算MD5值方法
 public static string GetMD5(string sDataIn)
  {
      MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
      byte[] bytValue, bytHash;
     bytValue = System.Text.Encoding.UTF8.GetBytes(sDataIn);
     bytHash = md5.ComputeHash(bytValue);
     md5.Clear();
     string sTemp = "";
      for (int i = 0; i < bytHash.Length; i++)
    {
        sTemp += bytHash[i].ToString("X").PadLeft(2, '0');
    }
    return sTemp.ToLower();
 }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章