Advertisement
here2share

# password_strength_demo.py

Jan 27th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. # password_strength_demo.py
  2.  
  3. rate='Weak1 Weak2 Medium3 Medium4 Strong5 Strong6 Excellent'.split()
  4. bad='''^(){}[]'`";\/<> '''
  5. sym=list('!@#$%&*_+-=:~?,.')
  6. num=list('0123456789')
  7.  
  8. def demo():
  9.     p=''
  10.     while 1:
  11.         if p is '':
  12.             p=raw_input("Enter New Password: ") # Replace raw_input with a text entry active bind in GUI
  13.         if len(set([i in p for i in bad])) < 2 and '\t' not in p:
  14.             s=4
  15.             p=unicode(p)
  16.             try:
  17.                 int(p)
  18.                 s=2; print 12345
  19.             except:
  20.                 if (p.lower() is p) or (p.upper() is p): s=3
  21.                 elif len(set([i in p for i in num])) is 2: s=5
  22.             t=len(set(list(p)))
  23.             if t < 8: s-=1
  24.             if t < 5: s-=1
  25.             if len(p) < 6: s-=1
  26.             if len(p) < 8: s-=1
  27.             if len(p) < 10: s-=1
  28.             if len(p) < 12: s-=1
  29.             if len(set([i in p for i in sym])) is 2 and s > 4: s+=1
  30.             if s < 0: s=0
  31.             if s > 6: s=6
  32.             print "Strength = %s (%s/6)" % (rate[s],s)
  33.             if len(p) > 5:
  34.                 yn=raw_input("Submit Password? (Y/N) ")
  35.                 p=yn
  36.                 if len(yn) < 5:
  37.                     p=''
  38.                     try:
  39.                         if yn.split()[0].lower() in ('y','yes'):
  40.                             print "Password Submitted"
  41.                             break
  42.                     except: pass
  43.             else: p=''
  44.         else:
  45.             print 'Sorry... spaces, tabs and all in the following... [ '+bad+']\n... are not acceptable.'
  46.             p=''
  47. demo()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement