国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net MD5的用法

2024-07-10 13:06:25
字體:
來源:轉載
供稿:網友

在asp.net中提供了加密的解決方法。在名字空間system.web.security中包含了類formsauthentication,其中有一個方法hashpasswordforstoringinconfigfile。這個方法可以將用戶提供的字符變成亂碼,然后存儲起來,甚至可以 存儲在cookies中。
hashpasswordforstoringinconfigfile方法使用起來很簡單,它支持"sha1"和"md5"加密算法。
下面的代碼簡單的演示了關于其用法:
<%@ page language="c#" %>
<%@ import namespace="system.web.security" %>
<html>
<head>
<script language="c#" runat="server">
public void encryptstring(object sender, eventargs e)
{
sha1.text = formsauthentication.hashpasswordforstoringinconfigfile(txtpassword.text,"sha1");
md5.text =formsauthentication.hashpasswordforstoringinconfigfile(txtpassword.text, "md5") ;
}
</script>
</head>
<body>
<form runat="server" id="form1">
<p>
<b>original clear text password: </b>
<br/>
<asp:textbox id="txtpassword" runat="server" />
<asp:button runat="server" text="encrypt string" onclick="encryptstring" id="button1" />
</p>
<p>
<b>encrypted password in sha1: </b>
<asp:label id="sha1" runat="server" />
</p>
<p>
<b>encrypted password in md5: </b>
<asp:label id="md5" runat="server" />
</p>
</form>
</body>
</html>


正如你所看到的這樣簡單易用。我們可以把這段加密程序封裝在一個函數里便于重復的使用。代碼如下:
public string encryptpassword(string passwordstring,string passwordformat )
{
if (passwordformat="sha1"){
encryptpassword=formsauthortication.hashpasswordforstoringinconfigfile(passwordstring ,"sha1");
}
elseif (passwordformat="md5")
{ encryptpassword=formsauthortication.hashpasswordforstoringinconfigfile(passwordstring ,"md5");
}
else
{
encryptpassword="";
}

注冊會員,創建你的web開發資料庫,
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 张掖市| 商南县| 娄烦县| 昆山市| 婺源县| 磐石市| 商南县| 舒兰市| 福清市| 丹棱县| 平远县| 吐鲁番市| 黄陵县| 贞丰县| 志丹县| 寿光市| 乌拉特前旗| 丁青县| 通州市| 思南县| 深泽县| 友谊县| 平乐县| 大化| 衡水市| 萝北县| 台安县| 如东县| 明溪县| 莒南县| 南通市| 静乐县| 华池县| 济南市| 专栏| 卫辉市| 甘孜县| 女性| 昔阳县| 恭城| 新乐市|