Membership Generate Password alphanumeric only password?

前端 未结 7 2119
独厮守ぢ
独厮守ぢ 2020-12-28 13:11

How can I use Membership.GeneratePassword to return a password that ONLY contains alpha or numeric characters? The default method will only guarantee a minimum and not a max

7条回答
  •  独厮守ぢ
    2020-12-28 13:35

    There is similar approach with breigo's solution. Maybe this is not so effective but so clear and short

    string GeneratePassword(int length)
    {
         var password = "";
         while (password.Length < length)
         {
              password += string.Concat(Membership.GeneratePassword(1, 0).Where(char.IsLetterOrDigit));
         }
         return password;
    }
    

提交回复
热议问题