encodeUtil.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. ** 登录密码加密
  3. http://face3d.4dage.com:7005/4dzfb-2.0/shop/src/master/platform-admin/src/main/webapp/login.html
  4. */
  5. function randomWord(randomFlag, min, max?) {
  6. let str = '';
  7. let range = min;
  8. const arr = [
  9. '0',
  10. '1',
  11. '2',
  12. '3',
  13. '4',
  14. '5',
  15. '6',
  16. '7',
  17. '8',
  18. '9',
  19. 'a',
  20. 'b',
  21. 'c',
  22. 'd',
  23. 'e',
  24. 'f',
  25. 'g',
  26. 'h',
  27. 'i',
  28. 'j',
  29. 'k',
  30. 'l',
  31. 'm',
  32. 'n',
  33. 'o',
  34. 'p',
  35. 'q',
  36. 'r',
  37. 's',
  38. 't',
  39. 'u',
  40. 'v',
  41. 'w',
  42. 'x',
  43. 'y',
  44. 'z',
  45. 'A',
  46. 'B',
  47. 'C',
  48. 'D',
  49. 'E',
  50. 'F',
  51. 'G',
  52. 'H',
  53. 'I',
  54. 'J',
  55. 'K',
  56. 'L',
  57. 'M',
  58. 'N',
  59. 'O',
  60. 'P',
  61. 'Q',
  62. 'R',
  63. 'S',
  64. 'T',
  65. 'U',
  66. 'V',
  67. 'W',
  68. 'X',
  69. 'Y',
  70. 'Z',
  71. ];
  72. // 随机产生
  73. if (randomFlag) {
  74. range = Math.round(Math.random() * (max - min)) + min;
  75. }
  76. for (let i = 0; i < range; i++) {
  77. const pos = Math.round(Math.random() * (arr.length - 1));
  78. str += arr[pos];
  79. }
  80. return str;
  81. }
  82. export function encodeStr(str, strv = ''): string {
  83. const NUM = 2;
  84. const front = randomWord(false, 8);
  85. const middle = randomWord(false, 8);
  86. const end = randomWord(false, 8);
  87. const str1 = str.substring(0, NUM);
  88. const str2 = str.substring(NUM);
  89. if (strv) {
  90. const strv1 = strv.substring(0, NUM);
  91. const strv2 = strv.substring(NUM);
  92. return [front + str2 + middle + str1 + end, front + strv2 + middle + strv1 + end];
  93. }
  94. return front + str2 + middle + str1 + end;
  95. }