一、文件---->新建----->网站----->空网站
右击website2---->添加新项------>web窗体--------->default.aspx
![](https://img.haomeiwen.com/i6083626/8d1b5236ef4bcba6.png)
![](https://img.haomeiwen.com/i6083626/f1a8aac2d7753bf1.png)
二、设计页面(TextBox1;Button1;Label1)
![](https://img.haomeiwen.com/i6083626/b46393d32916cfcc.png)
将button1--->属性---->Text:改为MD5加密
![](https://img.haomeiwen.com/i6083626/06f855152fc36d49.png)
三、写代码
在头部加上命名空间using System.Web.Security;
![](https://img.haomeiwen.com/i6083626/04985b8da5cf7ae3.png)
【default.aspx.cs】
附源码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string strtxt = TextBox1.Text;
Label1.Text = FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text, "MD5");
}
}
网友评论