asp.net应用.使用asp.net加密口令
【程序编程相关:2004-11-8】 当我们在网站上建立数据库时,保护用户的信息安全是非常必要的.多数用户不愿意让别人知道自己的信息,同时网管也不想因为安全问题而丢失网站的信誉.无论对于谁,安全问题都是非常重要的. 【推荐阅读:简化m文件转化为c/c++文件,VC编译】 【扩展信息:分析:解决m程序转化成cpp程序的编译问】为了解决这个问题,我给大家提供一个简单实用,但是老套的方法,就是口令加密.在此我们使用asp.net技术对口令加密.简单的讲,就是将用户提供的口令加密之后,然后让它与存放于系统中的数据比较,如果相同,则通过验证. 在asp中,并未提供加密的对象,我们只能使用外部的对象来进行加密.现在好了,在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> ... 下一页