123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- using System;
- 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位";
- }
- else if(ct>=3)
- {
- bool hasConsecutiveNumbersOrLetters = checkSame(pass);
-
- if (hasConsecutiveNumbersOrLetters)
- {
- ct=0;
- msg = "字符串包含连续的数字或字母。";
- }
- if(pass.Contains("oper")||pass.Contains("admin"))
- {
- ct=0;
- msg = "严禁在口令中包含英文单词或拼音";
- }
- if(pass.Contains("ftp@ftp.net"))
- {
- ct=0;
- msg = "严禁使用系统或应用的默认口令";
- }
- bool isTwoAdjacentKeys = IsTwoAdjacentKeys(pass);
-
- if(isTwoAdjacentKeys)
- {
- ct=0;
- msg = "位于键盘相邻位置的字符超过2位";
- }
- bool containsSimilar = ContainsSimilarString(pass);
-
- if(containsSimilar)
- {
- ct=0;
- msg = "含有与账号名、主机名、系统名、厂商名相同或相似的字符串";
- }
- bool isphone = NameJudgeFlage(pass,phoneNumber);
- bool isidCard = NameJudgeFlage(pass,idCard);
-
- if(isphone||isidCard)
- {
- ct=0;
- msg = "严禁含有与局房、人员姓名、生日、证件号码、电话号码、手机号码及门牌号码等";
- }
- }
-
-
- 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(inputold.text==inputnew1.text)
- {
- terror3.GetComponent<Text>().text = "新密码不能与旧密码一样";
- terror3.SetActive(true);
- return;
- }
- 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);
- }
-
-
- }
- private static readonly Regex _noConsecutiveNumbersRegex = new Regex(@"\d{3,}|[a-z]{3,}|[A-Z]{3,}");
-
- public static bool IsValidPassword(string password)
- {
- return _noConsecutiveNumbersRegex.IsMatch(password);
- }
- void savecloes()
- {
- savesuccess.SetActive(false);
- MainCenterManager.Instance.showMain();
- }
- static string NameJudge = "^[\u4e00-\u9fa5a-zA-Z0-9]{1,20}$";//字母、数字、汉字
- static string local = @"^[a-zA-Z]:((\\+[^\/:*?""<>|]+)+)\s*$"; //本地地址
- static string expression = "([hH][tT]{2}[pP]://|[hH][tT]{2}[pP][sS]://|[wW]{3}.|[wW][aA][pP].|[fF][tT][pP].|[fF][iI][lL][eE].)[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]";//网络地址
- static string email = @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$";//验证Email地址
- static string phoneNumber = @"^1(3[0-9]|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$";
- static string idCard = @"^\d{15}|\d{18}$";//验证身份证号(15位或18位数字)
- /// <summary>
- /// 正则表达式判断
- /// </summary>
- /// <param name="str">输入内容</param>
- /// <param name="regularExpression">正则表达式</param>
- /// <returns>是否符合输入格式</returns>
- public static bool NameJudgeFlage(string str, string regularExpression)
- {
- Regex reg = new Regex(regularExpression);//判断
- return reg.IsMatch(str);
- }
- // 定义键盘上的相邻字符
- private static readonly string[] adjacentKeys = new string[]
- {
- "qwertyuiop", "asdfghjkl", "zxcvbnm",
- "qaz", "wsx", "edc", "rfv", "tgb", "nhy", "ujm", "ik", "ol", "p;",
- "12", "34", "56", "78", "90",
- "QWERTYUIOP", "ASDFGHJKL", "ZXCVBNM",
- "QAZ", "WSX", "EDC", "RFV", "TGB", "NHY", "UJM", "IK", "OL", "P;",
- "12", "34", "56", "78", "90","ab","cd","ef","gh","ij","kl","mn","op","qr","st","uv","wx","yz"
- };
-
- // 正则表达式匹配两个相邻键盘字符
- private static readonly string pattern = string.Join("|", adjacentKeys).Replace("q", "[qQ]").Replace("w", "[wW]").Replace("s", "[sS]").Replace("d", "[dD]");
-
- public static bool IsTwoAdjacentKeys(string input)
- {
- return Regex.IsMatch(input, pattern);
- }
- //不能相同字符(如111、aaa)连续3位或3位以上
- public static bool checkSame(string str) {
- Regex _checkSame = new Regex(@"/(\w)\1{3,}/");
- return _checkSame.IsMatch(str);
- }
- // 正则表达式匹配规则,可以根据需要进行调整
- private static readonly string pattern2 = @"(账号名|主机名|系统名|厂商名)";
-
- // 检查字符串是否包含特定的字符串
- public static bool ContainsSimilarString(string input)
- {
- return Regex.IsMatch(input, pattern2, RegexOptions.IgnoreCase);
- }
- }
|