3

アプリケーションでasp.netメンバーシッププロバイダーを使用しています。また、「すぐに使用できる」asp:PasswordRecoveryコントロールも使用しています。

私のクライアントは、発行されている新しいパスワードが複雑すぎると不満を言っています。 例}>;-(hYrS ^ OTfY

新しいパスワードに文字と数字のみが含まれるように微調整することはできますか?

ありがとう!

4

1 に答える 1

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;
        }
    }

}

于 2009-12-11T16:51:16.003 に答える