123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- using System.Collections;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- using LitJson;
- using UnityEngine;
- using UnityEngine.UI;
- public class ChangePass : MonoBehaviour
- {
- public GameObject savesuccess;
- public GameObject terror;
- public GameObject terror2;
- public GameObject terror3;
- public InputField inputold;
- public InputField inputnew1;
- public InputField inputnew2;
- private void OnEnable() {
- inputnew1.text="";
- inputnew2.text="";
- inputold.text="";
- terror.SetActive(false);
- terror2.SetActive(false);
- terror3.SetActive(false);
- }
- public static passcheck checkpass(string pass)
- {
- int ct =0;
- string msg = "密码格式缺少:";
- var pwdRegex1 = "(?=.*[0-9])"; // 数字
- Regex reg1 = new Regex(pwdRegex1);
- bool isMatch1 = reg1.IsMatch(pass);
- if(!isMatch1)
- {
- msg += "数字 ";
- }
- else
- {
- ct++;
- }
- var pwdRegex2 = "(?=.*[a-z])"; // 小写字母
- Regex reg2 = new Regex(pwdRegex2);
- bool isMatch2 = reg2.IsMatch(pass);
- if(!isMatch2)
- {
- msg += "小写字母 ";
- }
- else
- {
- ct++;
- }
- var pwdRegex3 = "(?=.*[A-Z])"; // 大写字母
- Regex reg3= new Regex(pwdRegex3);
- bool isMatch3 = reg3.IsMatch(pass);
- if(!isMatch3)
- {
- msg += "大写字母 ";
- }
- else
- {
- ct++;
- }
- var pwdRegex4 = "[!@#$%^&*(),.?\\\":{}|<>]"; // 特殊字符
- Regex reg4= new Regex(pwdRegex4);
- bool isMatch4 = reg4.IsMatch(pass);
- if(!isMatch4)
- {
- msg += "特殊字符 ";
- }
- else
- {
- ct++;
- }
- msg+="中"+(3-ct)+"个";
- if(pass.Length<8)
- {
- msg = "密码必须大于8位";
- }
- passcheck p= new passcheck();
- p.ct = ct;
- p.msg=msg;
- return p;
- }
- public class passcheck
- {
- public int ct;
- public string msg;
- }
- public void changepass()
- {
- terror.SetActive(false);
- terror2.SetActive(false);
- terror3.SetActive(false);
- int ct = checkpass(inputnew1.text).ct;
- if(ct>=3&&inputnew1.text.Length>=8)
- {
- string oldpass = AesEncryption.Encrypt(inputold.text);
- string encrypted1 = AesEncryption.Encrypt(inputnew1.text);
- string encrypted2 = AesEncryption.Encrypt(inputnew2.text);
- if(encrypted1==encrypted2)
- {
- DataManager.Instance.setPass(oldpass,encrypted1,(msg) => {
- JsonData d = JsonMapper.ToObject(msg);
- if(d["data"]==null)
- {
- terror.SetActive(true);
- }
- else
- {
- terror2.SetActive(false);
- terror.SetActive(false);
- savesuccess.SetActive(true);
- Invoke("savecloes",2f);
- }
- });
- }
- else
- {
- terror2.SetActive(true);
- }
- }
- else
- {
- terror3.GetComponent<Text>().text = checkpass(inputnew1.text).msg;
- terror3.SetActive(true);
- }
-
-
- }
- void savecloes()
- {
- savesuccess.SetActive(false);
- MainCenterManager.Instance.showMain();
- }
- }
|