Asp.Net会员密码重置没有符号

时间:2009-08-27 01:20:09

标签: asp.net-membership membership sqlmembershipprovider

我在应用程序中使用asp.net成员资格提供程序。 我也在使用“开箱即用”的asp:PasswordRecovery控件。

我的客户抱怨发布的新密码太复杂了。 的 e.g。 }> ;-( hYrS ^ OTfY

我可以做一些小调整,所以新密码只包含字母和数字吗?

谢谢!

1 个答案:

答案 0 :(得分:4)

这有效:

    using System;
using System.Collections.Generic;
using System.Web.Profile;
using System.Web.Security;
using System.Text;

namespace TS.Common.MembershipProvider
{
    public class MembershipProvider : SqlMembershipProvider
    {
        /// Create an array of characters to user for password reset.
        /// Exclude confusing or ambiguous characters such as 1 0 l o i
        string[] characters = new string[] { "2", "3", "4", "5", "6", "7", "8",
            "9", "a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "m", "n",
            "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};

        const int DefaultResetPasswordLength = 10;
        private int ResetPasswordLength;

        // Create a more user friendly password to avoid confusion when
        // trying to key in the new value
        public override string GeneratePassword()
        {
            string newPassword = string.Empty;
            System.Random rnd = new Random();

            for (int i = 0; i < ResetPasswordLength; i++)
            {
                newPassword +=
                characters[rnd.Next(characters.GetUpperBound(0))];
            }
            return newPassword;
        }
    }

}