ChangePass.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using LitJson;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public class ChangePass : MonoBehaviour
  8. {
  9. public GameObject savesuccess;
  10. public GameObject terror;
  11. public GameObject terror2;
  12. public GameObject terror3;
  13. public InputField inputold;
  14. public InputField inputnew1;
  15. public InputField inputnew2;
  16. private void OnEnable() {
  17. inputnew1.text="";
  18. inputnew2.text="";
  19. inputold.text="";
  20. terror.SetActive(false);
  21. terror2.SetActive(false);
  22. terror3.SetActive(false);
  23. }
  24. public static passcheck checkpass(string pass)
  25. {
  26. int ct =0;
  27. string msg = "密码格式缺少:";
  28. var pwdRegex1 = "(?=.*[0-9])"; // 数字
  29. Regex reg1 = new Regex(pwdRegex1);
  30. bool isMatch1 = reg1.IsMatch(pass);
  31. if(!isMatch1)
  32. {
  33. msg += "数字 ";
  34. }
  35. else
  36. {
  37. ct++;
  38. }
  39. var pwdRegex2 = "(?=.*[a-z])"; // 小写字母
  40. Regex reg2 = new Regex(pwdRegex2);
  41. bool isMatch2 = reg2.IsMatch(pass);
  42. if(!isMatch2)
  43. {
  44. msg += "小写字母 ";
  45. }
  46. else
  47. {
  48. ct++;
  49. }
  50. var pwdRegex3 = "(?=.*[A-Z])"; // 大写字母
  51. Regex reg3= new Regex(pwdRegex3);
  52. bool isMatch3 = reg3.IsMatch(pass);
  53. if(!isMatch3)
  54. {
  55. msg += "大写字母 ";
  56. }
  57. else
  58. {
  59. ct++;
  60. }
  61. var pwdRegex4 = "[!@#$%^&*(),.?\\\":{}|<>]"; // 特殊字符
  62. Regex reg4= new Regex(pwdRegex4);
  63. bool isMatch4 = reg4.IsMatch(pass);
  64. if(!isMatch4)
  65. {
  66. msg += "特殊字符 ";
  67. }
  68. else
  69. {
  70. ct++;
  71. }
  72. msg+="中"+(3-ct)+"个";
  73. if(pass.Length<8)
  74. {
  75. msg = "密码必须大于8位";
  76. }
  77. passcheck p= new passcheck();
  78. p.ct = ct;
  79. p.msg=msg;
  80. return p;
  81. }
  82. public class passcheck
  83. {
  84. public int ct;
  85. public string msg;
  86. }
  87. public void changepass()
  88. {
  89. terror.SetActive(false);
  90. terror2.SetActive(false);
  91. terror3.SetActive(false);
  92. int ct = checkpass(inputnew1.text).ct;
  93. if(ct>=3&&inputnew1.text.Length>=8)
  94. {
  95. string oldpass = AesEncryption.Encrypt(inputold.text);
  96. string encrypted1 = AesEncryption.Encrypt(inputnew1.text);
  97. string encrypted2 = AesEncryption.Encrypt(inputnew2.text);
  98. if(encrypted1==encrypted2)
  99. {
  100. DataManager.Instance.setPass(oldpass,encrypted1,(msg) => {
  101. JsonData d = JsonMapper.ToObject(msg);
  102. if(d["data"]==null)
  103. {
  104. terror.SetActive(true);
  105. }
  106. else
  107. {
  108. terror2.SetActive(false);
  109. terror.SetActive(false);
  110. savesuccess.SetActive(true);
  111. Invoke("savecloes",2f);
  112. }
  113. });
  114. }
  115. else
  116. {
  117. terror2.SetActive(true);
  118. }
  119. }
  120. else
  121. {
  122. terror3.GetComponent<Text>().text = checkpass(inputnew1.text).msg;
  123. terror3.SetActive(true);
  124. }
  125. }
  126. void savecloes()
  127. {
  128. savesuccess.SetActive(false);
  129. MainCenterManager.Instance.showMain();
  130. }
  131. }