예제 #1
0
파일: UserModel.cs 프로젝트: burstas/rmps
        public bool WsSignPk(string oldPass, string newPass, XmlReader reader)
        {
            string code = null;
            if (reader.Name == "Code" || reader.ReadToFollowing("Code"))
            {
                code = reader.ReadElementContentAsString();
            }
            if (!CharUtil.IsValidateCode(code))
            {
                return false;
            }

            string data = null;
            if (reader.Name == "Data" || reader.ReadToFollowing("Data"))
            {
                data = reader.ReadElementContentAsString();
            }
            if (!Regex.IsMatch(data, "^[A-Za-z0-9+/=]{256,}$"))
            {
                return false;
            }

            string info = null;
            if (reader.Name == "Info" || reader.ReadToFollowing("Info"))
            {
                info = reader.ReadElementContentAsString();
            }
            if (!Regex.IsMatch(info, "^[A-Za-z0-9+/=]{44}$"))
            {
                return false;
            }

            string main = null;
            if (reader.Name == "Main" || reader.ReadToFollowing("Main"))
            {
                main = reader.ReadElementContentAsString();
            }
            if (!Regex.IsMatch(main, "^[A-Za-z0-9+/=]{108}$"))
            {
                return false;
            }

            string safe = null;
            if (reader.Name == "Safe" || reader.ReadToFollowing("Safe"))
            {
                safe = reader.ReadElementContentAsString();
            }

            _Data = Convert.FromBase64String(data);
            if (info != Digest(oldPass, newPass))
            {
                return false;
            }

            if (!Decrypt(oldPass, code, newPass, main))
            {
                return false;
            }

            DFAccess prop = new DFAccess();
            prop.Load(Path.Combine(this.DatHome, CApp.AMON_CFG));
            prop.Set(CApp.AMON_CFG_NAME, oldPass);
            prop.Set(CApp.AMON_CFG_CODE, code);
            prop.Set(CApp.AMON_CFG_DATA, data);
            prop.Set(CApp.AMON_CFG_INFO, info);
            prop.Set(CApp.AMON_CFG_LOCK, _Lock);
            prop.Set(CApp.AMON_CFG_MAIN, main);
            prop.Set(CApp.AMON_CFG_SAFE, safe);
            prop.Save(Path.Combine(this.DatHome, CApp.AMON_CFG));

            return true;
        }
예제 #2
0
파일: UserModel.cs 프로젝트: burstas/rmps
        /// <summary>
        /// 网络登录
        /// </summary>
        /// <returns></returns>
        public bool WsSignIn(string home, string code, string name, string pass, XmlReader reader)
        {
            string data = null;
            if (reader.Name == "Data" || reader.ReadToFollowing("Data"))
            {
                data = reader.ReadElementContentAsString();
            }
            if (!Regex.IsMatch(data, "^[A-Za-z0-9+/=]{256,}$"))
            {
                return false;
            }

            string info = null;
            if (reader.Name == "Info" || reader.ReadToFollowing("Info"))
            {
                info = reader.ReadElementContentAsString();
            }
            if (!Regex.IsMatch(info, "^[A-Za-z0-9+/=]{44}$"))
            {
                return false;
            }

            string main = null;
            if (reader.Name == "Main" || reader.ReadToFollowing("Main"))
            {
                main = reader.ReadElementContentAsString();
            }
            if (!Regex.IsMatch(main, "^[A-Za-z0-9+/=]{108}$"))
            {
                return false;
            }

            string safe = null;
            if (reader.Name == "Safe" || reader.ReadToFollowing("Safe"))
            {
                safe = reader.ReadElementContentAsString();
            }

            _Data = Convert.FromBase64String(data);
            if (info != Digest(name, pass))
            {
                return false;
            }

            if (!Decrypt(name, code, pass, main))
            {
                return false;
            }

            this.DatHome = home;
            DFAccess prop = new DFAccess();
            prop.Set(CApp.AMON_CFG_NAME, name);
            prop.Set(CApp.AMON_CFG_CODE, code);
            prop.Set(CApp.AMON_CFG_DATA, data);
            prop.Set(CApp.AMON_CFG_INFO, info);
            prop.Set(CApp.AMON_CFG_LOCK, info);
            prop.Set(CApp.AMON_CFG_MAIN, main);
            prop.Set(CApp.AMON_CFG_SAFE, safe);
            prop.Save(Path.Combine(this.DatHome, CApp.AMON_CFG));

            this.Name = name;
            this.Code = code;
            _Info = info;
            _Lock = info;
            Look = "Default";
            Feel = "Default";
            return true;
        }
예제 #3
0
파일: UserModel.cs 프로젝트: burstas/rmps
        /// <summary>
        /// 设定安全口令
        /// </summary>
        /// <param name="oldPass"></param>
        /// <param name="secPass"></param>
        /// <returns></returns>
        public bool CaAuthSk(string oldPass, string secPass)
        {
            DFAccess prop = new DFAccess();
            prop.Load(Path.Combine(this.DatHome, CApp.AMON_CFG));

            // 已有口令校验
            string info = Digest(Name, oldPass);
            if (info != prop.Get(CApp.AMON_CFG_INFO))
            {
                return false;
            }

            // 生成加密密钥及字符空间
            byte[] t = new byte[72];
            byte[] a = Encoding.UTF8.GetBytes(Code);
            int i = 0;
            Array.Copy(a, 0, t, i, a.Length);
            i += a.Length;
            Array.Copy(_Salt, 0, t, i, _Salt.Length);
            i += _Salt.Length;
            Array.Copy(_Keys, 0, t, i, _Keys.Length);
            i += _Keys.Length;
            a = Encoding.UTF8.GetBytes(_Mask);
            Array.Copy(a, 0, t, i, a.Length);

            // 口令
            byte[] k = GenK(Name, Code, secPass);
            // 向量
            byte[] v = GenV(Name, Code, secPass);

            #region AES 加密
            AesManaged aes = new AesManaged();
            using (MemoryStream mStream = new MemoryStream())
            {
                using (CryptoStream cStream = new CryptoStream(mStream, aes.CreateEncryptor(k, v), CryptoStreamMode.Write))
                {
                    cStream.Write(t, 0, t.Length);
                    cStream.FlushFinalBlock();
                    t = mStream.ToArray();
                }
            }
            aes.Clear();
            #endregion

            prop.Set(CApp.AMON_CFG_SAFE, Convert.ToBase64String(t));
            prop.Save(Path.Combine(this.DatHome, CApp.AMON_CFG));
            return true;
        }
예제 #4
0
파일: UserModel.cs 프로젝트: burstas/rmps
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <returns></returns>
        public bool CaSignUp(string root, string code, string name, string pass)
        {
            byte[] k = GenK(name, code, pass);
            byte[] v = GenV(name, code, pass);

            Random r = new Random();
            _Salt = new byte[16];
            r.NextBytes(_Salt);
            _Keys = new byte[32];
            r.NextBytes(_Keys);
            _Mask = GenChar();

            byte[] t = new byte[72];
            byte[] a = Encoding.UTF8.GetBytes(code);
            int i = 0;
            Array.Copy(a, 0, t, i, a.Length);
            i += a.Length;
            Array.Copy(_Salt, 0, t, i, _Salt.Length);
            i += _Salt.Length;
            Array.Copy(_Keys, 0, t, i, _Keys.Length);
            i += _Keys.Length;
            a = Encoding.UTF8.GetBytes(_Mask);
            Array.Copy(a, 0, t, i, a.Length);

            #region AES 加密
            AesManaged aes = new AesManaged();
            using (MemoryStream mStream = new MemoryStream())
            {
                using (CryptoStream cStream = new CryptoStream(mStream, aes.CreateEncryptor(k, v), CryptoStreamMode.Write))
                {
                    cStream.Write(t, 0, t.Length);
                    cStream.FlushFinalBlock();
                    t = mStream.ToArray();
                }
            }
            aes.Clear();
            #endregion
            string main = Convert.ToBase64String(t);

            _Data = new byte[256];
            r.NextBytes(_Data);
            string info = Digest(name, pass);

            this.DatHome = Path.Combine(root, code);
            if (!Directory.Exists(this.DatHome))
            {
                Directory.CreateDirectory(this.DatHome);
            }
            DFAccess prop = new DFAccess();
            prop.Set(CApp.AMON_CFG_NAME, name);
            prop.Set(CApp.AMON_CFG_CODE, code);
            prop.Set(CApp.AMON_CFG_DATA, Convert.ToBase64String(_Data));
            prop.Set(CApp.AMON_CFG_INFO, info);
            prop.Set(CApp.AMON_CFG_LOCK, info);
            prop.Set(CApp.AMON_CFG_MAIN, main);
            prop.Set(CApp.AMON_CFG_SAFE, "");
            prop.Save(Path.Combine(this.DatHome, CApp.AMON_CFG));

            this.Name = name;
            this.Code = code;
            _Info = info;
            _Lock = info;
            Look = "Default";
            Feel = "Default";
            return true;
        }
예제 #5
0
파일: UserModel.cs 프로젝트: burstas/rmps
        /// <summary>
        /// 设定锁屏口令
        /// </summary>
        /// <returns></returns>
        public bool CaAuthLk(string oldPass, string newPass)
        {
            if (_Lock != Digest(this.Name, oldPass))
            {
                return false;
            }

            _Lock = Digest(Name, newPass);

            DFAccess prop = new DFAccess();
            prop.Load(Path.Combine(this.DatHome, CApp.AMON_CFG));
            prop.Set(CApp.AMON_CFG_LOCK, _Lock);
            prop.Save(Path.Combine(this.DatHome, CApp.AMON_CFG));
            return true;
        }