Membership.GeneratePassword 不符合 numberOfNonAlphaNumericCharacters
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该文档已过时。试试这个:
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
我只使用 .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!