password_handle.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #coding=utf-8
  2. '''
  3. @attention: 密码加密验证模块
  4. '''
  5. import hashlib
  6. import re
  7. import common.error_info as ceil
  8. import random
  9. def check_password(new,old):
  10. """
  11. @attention: 验证密码
  12. """
  13. np = hashlib.md5(new).hexdigest().upper()
  14. return np==old
  15. def make_password(pwd,isdefault=None):
  16. """
  17. @attention: 密码加密
  18. """
  19. #if not re.search(r'^.*(?=.{6,15})(?=.*\d)(?=.*[A-Z]{1,})(?=.*[a-z]{1,})(?=.*[!@#$%^&*?\(\)]).*$',pwd) and not isdefault:
  20. # raise ceil.TipException(u"密码不符合符号要求!")
  21. return hashlib.md5(pwd).hexdigest().upper()
  22. def make_default_password(pwd):
  23. """
  24. @attention: 密码加密
  25. """
  26. ustr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  27. lstr = "abcdefghjklmnopqrstuvwxyz"
  28. dstr = "0123456789"
  29. sstr = "!@#$%&*"
  30. pwd = "".join(random.sample(ustr,3)+random.sample(lstr,3)+random.sample(dstr,3)+random.sample(sstr,3))
  31. return pwd,hashlib.md5(pwd).hexdigest().upper()
  32. if __name__ == '__main__':
  33. old = "123456"
  34. op = make_password(old)
  35. # print op
  36. new = "123456"
  37. # print check_password(new, op)