password_handle.py 848 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. """
  12. np = hashlib.md5(new).hexdigest().upper()
  13. return np==old
  14. def make_password(pwd,isdefault=None):
  15. """
  16. """
  17. return hashlib.md5(pwd).hexdigest().upper()
  18. def make_default_password(pwd):
  19. """
  20. @attention: 密码加密
  21. """
  22. ustr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  23. lstr = "abcdefghjklmnopqrstuvwxyz"
  24. dstr = "0123456789"
  25. sstr = "!@#$%&*"
  26. pwd = "".join(random.sample(ustr,3)+random.sample(lstr,3)+random.sample(dstr,3)+random.sample(sstr,3))
  27. return pwd,hashlib.md5(pwd).hexdigest().upper()
  28. if __name__ == '__main__':
  29. old = "root"
  30. op = make_password(old)
  31. print op
  32. new = "123456"
  33. # print check_password(new, op)