欢迎光临
我们一直在努力

用XML代替數據庫來實現WEB的窗體認証-.NET教程,XML应用

建站超值云服务器,限时71元/月

最近看了一些c#操作xml的資料﹐感覺與操作sql等沒有什么區別﹐于是簡單地寫了一個加密的用于實現登入web網頁在認証程序,供大家參考:

1﹑在form中添加兩個textbox和一個button控件﹐一個textbox id為username,一個為userpwd.2﹑在form中引入system.web.security和system.io兩個類.3﹑開始寫button的響應代碼: private void ok_click(object sender, system.eventargs e) { string cmd="username="+username.text.trim()+""; dataset ds=new dataset(); filestream fs=new filestream(server.mappath("users.xml"),filemode.open,fileaccess.read); streamreader reader=new streamreader(fs); ds.readxml(reader); fs.close(); datatable users=ds.tables[0]; datarow[] matches=users.select(cmd); if(matches!=null && matches.length>0) { datarow row=matches[0]; string hashedpwd=formsauthentication.hashpasswordforstoringinconfigfile(userpwd.text.trim(),"sha1"); string pass=(string)row["userpassword"]; if(string.compare(pass,hashedpwd,false)!= 0) { response.write("密碼不正確!"); } else { formsauthentication.setauthcookie(useremail.text,false); response.ridirect(“default.aspx“); } } else { response.write(“無此用戶!“); } }3﹑其中的密碼是用了哈稀算法。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 用XML代替數據庫來實現WEB的窗體認証-.NET教程,XML应用
分享到: 更多 (0)

相关推荐

  • 暂无文章