editprofile.ui.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. let password1Encrypted = false;
  2. let password2Encrypted = false;
  3. let verifyEncrypted = false;
  4. /**
  5. * 密码改变时标记密码未加密。
  6. * Mark password unencrypted when password changes.
  7. *
  8. * @param event event
  9. * @access public
  10. * @return void
  11. */
  12. function changePassword(event)
  13. {
  14. const targetID = $(event.target).attr('id');
  15. if(targetID == 'password1') password1Encrypted = false;
  16. if(targetID == 'password2') password2Encrypted = false;
  17. if(targetID == 'verifyPassword') verifyEncrypted = false;
  18. }
  19. /**
  20. * 加密密码并记录密码强度和长度。
  21. * Encrypt password and record password strength and length.
  22. *
  23. * @access public
  24. * @return void
  25. */
  26. function encryptPassword()
  27. {
  28. const rand = $('input[name=verifyRand]').val();
  29. /* 加密当前登录用户的密码。*/
  30. /* Encrypt password of current user. */
  31. if($('input#verifyPassword').length > 0)
  32. {
  33. const password = $('input#verifyPassword').val().trim();
  34. if(password && !verifyEncrypted)
  35. {
  36. $('input#verifyPassword').val(md5(md5(password) + rand));
  37. verifyEncrypted = true;
  38. }
  39. }
  40. if($('#password1').length == 0 || $('#password2').length == 0) return;
  41. /* 加密新添加用户或被修改用户的密码 1,并记录密码强度和长度。*/
  42. /* Encrypt password 1 of new or modified user, and record password strength and length. */
  43. const password1 = $('#password1').val().trim();
  44. if(password1 && !password1Encrypted)
  45. {
  46. $('#password1').val(md5(password1) + rand);
  47. $("input[name=passwordStrength]").val(computePasswordStrength(password1));
  48. $("input[name=passwordLength]").val(password1.length);
  49. password1Encrypted = true;
  50. }
  51. /* 加密新添加用户或被修改用户的密码 2。*/
  52. /* Encrypt password 2 of new or modified user. */
  53. const password2 = $('#password2').val().trim();
  54. if(password2 && !password2Encrypted)
  55. {
  56. $('#password2').val(md5(password2) + rand);
  57. password2Encrypted = true;
  58. }
  59. }