title: How to create a brute-force password cracker for alphabetical and alphanumerical passwords?
body: <p>I'm trying to create a brute force Python code for alphabetical and alphanumerical combinations and have it report the password and amount of time it took.</p>
  <p>For numerical combinations I made this:</p>
  <pre><code>import datetime as dt
  
  Password4 = 123456
  
  def crack_password():
      start = dt.datetime.now()
      for n in range(1000000):
          password_guess = '{0:04d}'.format(n)
               if password_guess == str(Password4):
                  end = dt.datetime.now()
                  print(&quot;Password found: {} in {}&quot;.format(password_guess, end - start))
                 break
      guesses = crack_password()
  </code></pre>
  <p>For alphanumerical combinations (does not work) I tried:</p>
  <pre><code>import random
  
  letters = [str(i) for i in range('a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p')]
  s = [''.join([a,b,c,d,e,f,g,h]) for a in letters for b in letters for c   in letters for d in letters for e in letters for f in letters for g in letters  for h in letters]
  random.shuffle(s)
  real_password = 'aaaaaaaa'
  i = 0
  
  for code in s:
  if code == real_password:
      print()
          print('The password is: ', code)
          break
      else:
          i += 1
          print(i, ' failures', end='\r')
  </code></pre>
  <p>It should report either number of attempts or time it took.</p>