自动生成的密钥不支持哈希或加密密码

发布于 2024-07-13 10:57:38 字数 993 浏览 6 评论 0原文

我已经创建了一个会员提供程序并将我的 web.config 更改为,

<membership defaultProvider="MyMembershipProvider">
   <providers>
     <clear/>
     <add name="MyMembershipProvider"
          type="Khafan.Providers.SqlMembershipProvider"
          connectionStringName="KhafanConnectionString"  
          maxInvalidPasswordAttempts="5"             
          passwordAttemptWindow="10"
          minRequiredNonalphanumericCharacters="0"
          minRequiredPasswordLength="4"
          passwordStrengthRegularExpression=""
          passwordFormat="Hashed"
          enablePasswordReset="true"
          enablePasswordRetrieval="false"             
          requiresQuestionAndAnswer="false"
          requiresUniqueEmail="true" />
   </providers>
 </membership>

但现在,每当我尝试浏览 ASP.Net 配置的安全页面时,都会出现以下错误:

自动生成的密码不支持散列或加密密码 在我的数据库中,

我使用 Identity 作为我的 PK。 我不知道这是不是问题。 但如果是的话我该如何解决呢? 我不想更改身份值。

谢谢。

I have create a Membership provider and changed my web.config to

<membership defaultProvider="MyMembershipProvider">
   <providers>
     <clear/>
     <add name="MyMembershipProvider"
          type="Khafan.Providers.SqlMembershipProvider"
          connectionStringName="KhafanConnectionString"  
          maxInvalidPasswordAttempts="5"             
          passwordAttemptWindow="10"
          minRequiredNonalphanumericCharacters="0"
          minRequiredPasswordLength="4"
          passwordStrengthRegularExpression=""
          passwordFormat="Hashed"
          enablePasswordReset="true"
          enablePasswordRetrieval="false"             
          requiresQuestionAndAnswer="false"
          requiresUniqueEmail="true" />
   </providers>
 </membership>

but now, whenever I try to browse to security page of ASP.Net Configuration it gives me the following error:

Hashed or Encrypted passwords are not supported with auto-generated keys

In my database I have used Identity for my PKs. I don't know it is the problem or not. But if it is, how can I solve it? I don't want to change Identity values.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

微凉 2024-07-20 10:57:38

这是因为您正在对密码进行哈希处理,但尚未在 web.config 中设置特定的密钥。 这篇MSDN文章中有一个“密钥生成器”片段,运行它两次并将它们放入您的 web.config 中:

<system.web>
    <machineKey  
    validationKey="<blah>"           
    decryptionKey="<blah>"
    validation="SHA1"
    decryption="AES"
    />

这应该可以解决您的问题。 之所以会这样,是因为否则您可以将会员数据库/应用程序带到另一台计算机上,并且您的密码都不起作用,因为自动生成的计算机密钥会有所不同:-)

This is because you are hashing passwords but haven't set specific keys in your web.config. There's a "key generator" snippet in this MSDN article, run it twice and shove them in your web.config as:

<system.web>
    <machineKey  
    validationKey="<blah>"           
    decryptionKey="<blah>"
    validation="SHA1"
    decryption="AES"
    />

And that should sort you out. It's like this because otherwise you could take your membership database/app to another machine and none of your passwords would work, as the auto generated machine keys would be different :-)

℉絮湮 2024-07-20 10:57:38

去寻找“密钥生成器”片段有点笨拙
MSDN 链接 Steven Robbins 在他的回答中提到了,所以我添加放在这里以供快速参考。 所以这不是一个独立的答案。 它是对已接受答案的补充。

来自 MSDN

下面的代码展示了如何
生成随机键值。 编译
创建控制台的代码
申请,然后通过
作为命令行所需的密钥大小
参数表达为期望的
十六进制字符数。 每个
byte由两个十六进制表示
人物; 因此,要求
32字节密钥,将64作为命令行传递
争论。 如果您不指定
参数,代码返回 128
十六进制字符(64 字节)密钥。

using System;
using System.Text;
using System.Security;
using System.Security.Cryptography;

class App {
  static void Main(string[] argv) {
    int len = 128;
    if (argv.Length > 0)
      len = int.Parse(argv[0]);
    byte[] buff = new byte[len/2];
    RNGCryptoServiceProvider rng = new 
                            RNGCryptoServiceProvider();
    rng.GetBytes(buff);
    StringBuilder sb = new StringBuilder(len);
    for (int i=0; i<buff.Length; i++)
      sb.Append(string.Format("{0:X2}", buff[i]));
    Console.WriteLine(sb);
  }
}

此外, 位于 内部,如下所示:

<system.web>
    <machineKey
        validationKey=""
        decryptionKey=""
        validation="SHA1"
        decryption="AES"
/>

Was a bit of a schlep to go hunting for the "key generator" snippet in the
MSDN link Steven Robbins referred to in his answer, so I am adding it here for quick reference. So this is not a standalone answer. It is supplemental to the accepted answer.

FROM MSDN

The following code shows how to
generate random key values. Compile
the code to create a console
application, and then pass the
required key size as a command line
argument expressed as the desired
number of hexadecimal characters. Each
byte is represented by two hexadecimal
characters; therefore, to request a
32-byte key, pass 64 as a command line
argument. If you do not specify an
argument, the code returns a 128
hexadecimal character (64-byte) key.

using System;
using System.Text;
using System.Security;
using System.Security.Cryptography;

class App {
  static void Main(string[] argv) {
    int len = 128;
    if (argv.Length > 0)
      len = int.Parse(argv[0]);
    byte[] buff = new byte[len/2];
    RNGCryptoServiceProvider rng = new 
                            RNGCryptoServiceProvider();
    rng.GetBytes(buff);
    StringBuilder sb = new StringBuilder(len);
    for (int i=0; i<buff.Length; i++)
      sb.Append(string.Format("{0:X2}", buff[i]));
    Console.WriteLine(sb);
  }
}

Also, <machineKey> goes inside of <system.web>, like this:

<system.web>
    <machineKey
        validationKey=""
        decryptionKey=""
        validation="SHA1"
        decryption="AES"
/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文