【问题标题】:How to match user name and password using FormsAuthentication如何使用 FormsAuthentication 匹配用户名和密码
【发布时间】:2014-01-04 06:25:13
【问题描述】:

C#

protected void btnLogin_Click(object sender, EventArgs e)
    {

        if(FormsAuthentication.Authenticate(txtName.ToString(),txtPass.ToString()))
        {
             Response.Redirect("admin.aspx");
        }
         else
        {
            Response.Redirect("user.aspx");
        }
    }

配置:

<authentication mode="Forms"> 
 <forms loginUrl="login.aspx" timeout="2880" defaultUrl="~/" > 
  <credentials passwordFormat="SHA1"> 
  <user name="mohit" password="mohit"/> 
  </credentials> 
 </forms> 
</authentication>

它没有重定向到管理页面。每当我登录时,其他条件都会起作用。

【问题讨论】:

  • 至少你应该提一下我的朋友出了什么问题
  • 它没有重定向到管理页面。每当我登录时,其他条件都会起作用

标签: asp.net c#-4.0 forms-authentication


【解决方案1】:

试试这样吧:

    if(FormsAuthentication.Authenticate(txtName.Text, txtPass.Text))
    {
         Response.Redirect("admin.aspx");
    }
    else
    {
        Response.Redirect("user.aspx");
    }

【讨论】:

  • 我知道这一点,但不是解决方案它不起作用
  • 你的问题不是很清楚,txtNametextPass是什么
  • 您的密码值应使用 SHA1 进行哈希处理,因此应如下所示:&lt;user name="mohit" password="9944BB848BBSDS"/&gt;
【解决方案2】:

// 在凭据标签中将 passwordFormat="SHA1" 设置为 passwordFormat="Clear"

 <authentication mode="Forms" >
      <forms loginUrl ="Default.aspx" DefaultUrl="~/admin.aspx">
        <credentials passwordFormat="Clear">
          <user name="mohit" password="mohit"/> 
        </credentials>
      </forms>
    </authentication>
    <authorization>
      <deny users ="?"/>
    </authorization> 

它对我有用。

【讨论】:

    【解决方案3】:

    将 PasswordFormat 更改为 Clear(即 passwordFormat="Clear"),因为当您将 Password format 提及为 SHA1(它是一种算法)时,表单身份验证将永远不会将纯文本密码与 algorithm 的 @987654323 进行比较@ 98ahcnd15。在 下的 web.config 文件中使用授权标签。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-18
      • 2021-04-10
      • 2016-05-09
      • 2014-05-20
      • 2020-05-01
      • 1970-01-01
      • 2017-05-27
      • 1970-01-01
      相关资源
      最近更新 更多