|
发表于 2006-11-6 19:28:31
|
显示全部楼层
你可以这样写,首先修改Web.config。
<authentication mode="Forms">
<forms name="Squares" loginUrl="Login.aspx" cookieless="AutoDetect">
<credentials passwordFormat="SHA1">
<user name="Admin" password="49BB030CFC2F51560577C278300AD3E9ABBEF573"/>
</credentials>
</forms>
</authentication>
然后制作一个Login.aspx,里面放两个输入框和一个登录按钮。
在按钮事件里写上如下代码。
protected void btnOK_Click(object sender, EventArgs e)
{
if (FormsAuthentication.Authenticate(txtUser.Text, txtPassword.Text))
{
if (Request.QueryString["ReturnUrl"] != null)
{
FormsAuthentication.RedirectFromLoginPage(txtUser.Text, false);
}
else
{
FormsAuthentication.SetAuthCookie(txtUser.Text, false);
}
}
else
{
lblLoginResult.Visible = true;
}
}
至于Web.config中加密的密码,可以通过如下的语句获得。
string strHasValue = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "SHA1");
将运算后的strHasValue里的值,拷贝到Web.config对应的位置
[ 本帖最后由 xujh 于 2006-11-6 19:31 编辑 ] |
|