asp.net - 无法检索散列密码。将密码格式设置为不同类型,或将 enablePasswordRetrieval 设置为 false

标签 asp.net .net asp.net-mvc-2

我有一些网站,现在我想获取密码。

我用这个:

<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider"
             connectionStringName="TravelChamps" 
enablePasswordRetrieval="true"
             enablePasswordReset="true"
             requiresQuestionAndAnswer="false"
             requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" 
             minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"             
             />

发生此错误:

配置的设置无效:无法检索散列密码。将密码格式设置为不同类型,或将 enablePasswordRetrieval 设置为 false。

如果我使用它:
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider"
             connectionStringName="TravelChamps" enablePasswordRetrieval="false"
             enablePasswordReset="true"
             requiresQuestionAndAnswer="false"
             requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" 
             minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"             
             />

我收到以下错误:

检索您的密码时发生异常:此成员(member)资格提供商尚未配置为支持密码检索。

我完全糊涂了。

有什么建议可以开始解决吗?

最佳答案

如果您希望可以检索密码或将它们作为纯文本(未加密)获取,则必须在创建第一个用户之前更改 The Membership 的某些配置。

执行以下任务(它与asp net有关):

1.在文件web.config中,在标签membership/providers/add set attributes中:

enablePasswordRetrieval="true"<br/>
passwordFormat="Encrypted"

我的设置:
<membership>
  <providers>
    <clear/>
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider"     connectionStringName="maindb"
         enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
         maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
         applicationName="/" passwordFormat="Encrypted" />
  </providers>
</membership>

2.生成所谓的validationKey和decryptionKey。您可以通过 NET API 执行此操作:

我的例子:
public static class RNGCrypto_MachineKey
{
    public static string getRandomKey(int bytelength)
    {
        byte[] buff = new byte[bytelength];
        RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
        rng.GetBytes(buff);
        StringBuilder sb = new StringBuilder(bytelength * 2);
        for (int i = 0; i < buff.Length; i++)
            sb.Append(string.Format("{0:X2}", buff[i]));
        return sb.ToString();
    }
}

生成:
string key64 = RNGCrypto_MachineKey.getRandomKey(64);
string key32 = RNGCrypto_MachineKey.getRandomKey(32);

3. 同样,在文件 web.config 中,在标签 system.web 中放置以下设置:
    <machineKey validationKey="paste here the key64 string" decryptionKey="paste here the key32 string" validation="SHA1"/>

( about machinkey on msdn )

4.现在您可以使用密码创建用户,然后您可以获得普通密码:
Membership.GetUser(username).GetPassword();

关于asp.net - 无法检索散列密码。将密码格式设置为不同类型,或将 enablePasswordRetrieval 设置为 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8918465/

相关文章:

asp.net-mvc-2 - ASP.net MVC 2 应用程序教程,使用带有许多表的 Entity Framework

asp.net - 我的文字不是html?

asp.net - 将 RouteValues 读入 Controller

c# - 如何使用 SharpSSH 或 SSH.NET 库在 SFTP 服务器上附加文本文件

asp.net - asp.net session 大小多少算太大?

c# - Process.从用户机器开始

c# - 用于处理连续消息流的响应式(Reactive)扩展

asp.net-mvc-2 - Asp.Net MVC 2 中的强类型 ActionLink?

jquery - 为什么我无法使用 GET 向 WebMethod 发送参数?

javascript - 来自javascript问题的asp下拉列表动态值