Membership.GeneratePassword 不符合 numberOfNonAlphaNumericCharacters

发布于 2024-08-13 08:06:58 字数 1626 浏览 1 评论 0原文

我正在使用 Membership.GeneratePassword(10, 0)。

即,根据 MSDN 定义,非字母数字字符的数量应为零: http://msdn.microsoft.com/en-us/library/system.web.security.membership.generatepassword(VS.80).aspx

但是,我注意到这不符合我的预期。算法中是否存在错误,或者看到这一点是正常的吗?当我期望看到零时,我仍然在生成的密码中看到相当数量的标点符号字符。

作为测试,我在 ASP.NET 页面上放置了一个网格,并编写了以下代码来查看输出是什么:

public partial class Verification : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int max = 0; // change as required
        List<MemberPassword> list = new List<MemberPassword>();
        for (int i = 0; i <= 20; i++)
        {
            for (int j = 0; j <= max; j++)
            {
                string display = String.Format("Membership.GeneratePassword(10, {0})", j);
                list.Add(new MemberPassword(i, j, Membership.GeneratePassword(10, j), display));
            }
        }

        this.GridView1.DataSource = list;
        this.GridView1.DataBind();
    }
}

public class MemberPassword
{
    public MemberPassword(int id, int numNonAlphaNum, string password, string display)
    {
        this.Id = id;
        this.NumNonAlphaNum = numNonAlphaNum;
        this.Password = password;
        this.Display = display;
    }

    public int Id { get; set; }
    public int NumNonAlphaNum { get; set; }
    public string Password { get; set; }
    public string  Display { get; set; }
}

尽管结果显示标点符号越来越多,但实际要求并未得到满足。

我是不是搞错了方向,还是我失去了情节? :-)

I'm using Membership.GeneratePassword(10, 0).

i.e. Number of Non-AlphaNumeric characters should be zero, as per the MSDN defintion: http://msdn.microsoft.com/en-us/library/system.web.security.membership.generatepassword(VS.80).aspx

However, I noted that this didn't conform to what I expected. Is there a bug in the algorithm, or is it normal to see this? I still see a fair amount of punctuation characters in the password that is generated when I expect to see zero.

As a test, I threw a Grid on an ASP.NET page and wrote this to see what the output was:

public partial class Verification : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int max = 0; // change as required
        List<MemberPassword> list = new List<MemberPassword>();
        for (int i = 0; i <= 20; i++)
        {
            for (int j = 0; j <= max; j++)
            {
                string display = String.Format("Membership.GeneratePassword(10, {0})", j);
                list.Add(new MemberPassword(i, j, Membership.GeneratePassword(10, j), display));
            }
        }

        this.GridView1.DataSource = list;
        this.GridView1.DataBind();
    }
}

public class MemberPassword
{
    public MemberPassword(int id, int numNonAlphaNum, string password, string display)
    {
        this.Id = id;
        this.NumNonAlphaNum = numNonAlphaNum;
        this.Password = password;
        this.Display = display;
    }

    public int Id { get; set; }
    public int NumNonAlphaNum { get; set; }
    public string Password { get; set; }
    public string  Display { get; set; }
}

Although the results show a progression towards more and more punctuation, the actual requirement is not honoured.

Have I got the wrong end of the stick here or am I losing the plot? :-)

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

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

发布评论

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

评论(2

荒人说梦 2024-08-20 08:06:58

该文档已过时。试试这个:

http://msdn. microsoft.com/en-us/library/system.web.security.membership.generatepassword.aspx

生成的密码中的最少标点字符数。

That documentation is out of date. Try this one:

http://msdn.microsoft.com/en-us/library/system.web.security.membership.generatepassword.aspx

The minimum number of punctuation characters in the generated password.

天涯离梦残月幽梦 2024-08-20 08:06:58

我只使用 .NET 2.0,所以我认为这是一个错误,或者更可能是他们的 .NET 2.0 文档中的打印错误,因为在 3.0 及更高版本中,他们有单词最小值

I am only using .NET 2.0 so I think this is a bug, or more likely a mis-print in their .NET 2.0 documentation seeing as in 3.0 and above they have the word minimum!

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