mardi 8 novembre 2016

C# generate random password - limit occurrences of letters/numbers

I'm trying to generate a random password in C#, I have tried this:

var password = Membership.GeneratePassword(10, 2);

However this does not quite fit my needs, as I want the generated passwords to conform to the following rules:

  • Must be at least 8 characters long
  • Must contain at least 4 alphabetic characters
  • Must contain at least one digit
  • Must not contain more than two occurrences of any one character or digit

There are various random password solutions already out there but all the ones I have found do not take the last rule into account. Surely there an easy and elegant way to do this?




Aucun commentaire:

Enregistrer un commentaire