[Math] Number of possible passwords for password policy

combinationspermutations

Supposed we have a password policy with the following requirements:

  • Can only contain lower letter, upper letter or digits (a-zA-Z0-9)
  • Must have 8-chars
  • Must start with a lower letter (a-z)
  • Must have at least one number (0-9)
  • Must have at least one lower letter (a-z)
  • Must have at least one upper letter (A-Z)

How do i calculate the number of all possible combinations?

Best Answer

The condition that the first letter be lower case automatically satisfies the later condition that there be at least one lower case letter present, so we may ignore that condition in the rest of our calculations.

We ask the sub-question: how many $7$-character passwords with at least one uppercase letter and at least one number are there? We approach by inclusion-exclusion.

Let $A$ be the set of 7-character passwords which contain at least one uppercase letter and $B$ the set of 7-character passwords which contain at least one number. Let $S$, our universal set, be the set of 7-character passwords regardless of either of those two conditions. We are searching then for the value of $|A\cap B|$.

By De'Morgan's $|A\cap B|=|S\setminus (A^c\cup B^c)|$ which by inclusion-exclusion is $|S|-|A^c|-|B^c|+|A^c\cap B^c|$

We have $|S|=(10+26+26)^7=62^7$

We have $|A^c|=(10+26+0)^7=36^7$

We have $|B^c|=(0+26+26)^7=52^7$

We have $|A^c\cap B^c|=(0+26+0)^7=26^7$

We have the total number of $7$-character passwords with at least one uppercase letter and at least one number are $62^7-36^7-52^7+26^7$

Finally, since any 8-character passwords satisfying your conditions can be uniquely described as a lower case letter followed by a 7-character password with at least one uppercase and at least one number, we bring our final total for the original problem to:

$26\cdot (62^7-36^7-52^7+26^7)=63003474293760$